I have a Menu with 5 Menus as:
Menu Name Menu Text
M1 File
M2 Edit
M3 View
M4 Insert
I want to execute the code depending upon which menu is clicked. Since most
of the code is same therefore, I want to write the one procedure. Therefore
I tried to write something like...
Private Sub Menu_Click (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _
M1.Click, M2.Click, M3.Click, M4.Click
******************
*****************
*************
x = sender.text
msgbox (x)
********
End Sub
When I click the message box shows the Text property of menu i.e. if I click
M1 it shows "File", if I click M2 it shows "Edit" etc. However, I want to
show Name i.e. when I click M1 it should show M1, when I click M2 it should
show M2, and so on.
The second thing I want to ask is that why is that when we type SENDER and
the type dot (.) it doesn't show properties or methods associated with the
sender. However, still we can type TEXT. How would we know what other
methods or properties are associated with SENDER OBJECT.
Thanks in advance! 8 1368
I can handle the second half of oyur question.
the SENDER object is late bound - it is defined purely as an "object", it
doesn't actually take the form of a menu item until runtime. Therefore the
intellisense in the IDE doesn't know the methods that could be applicable as
it doesn't know the type of object it is .
HTH
Simon
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:eA***************@tk2msftngp13.phx.gbl... I have a Menu with 5 Menus as:
Menu Name Menu Text M1 File M2 Edit M3 View M4 Insert
I want to execute the code depending upon which menu is clicked. Since
most of the code is same therefore, I want to write the one procedure.
Therefore I tried to write something like...
Private Sub Menu_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _ M1.Click, M2.Click, M3.Click, M4.Click
****************** ***************** *************
x = sender.text msgbox (x)
******** End Sub
When I click the message box shows the Text property of menu i.e. if I
click M1 it shows "File", if I click M2 it shows "Edit" etc. However, I want to show Name i.e. when I click M1 it should show M1, when I click M2 it
should show M2, and so on.
The second thing I want to ask is that why is that when we type SENDER and the type dot (.) it doesn't show properties or methods associated with the sender. However, still we can type TEXT. How would we know what other methods or properties are associated with SENDER OBJECT.
Thanks in advance!
Hi Don,
I still get a chuckle out of that name! And you? ;-))
Sender is, as Simon pointed out, a 'pure object' which Intellisense can't
fathom beyond its 'objectness'.
You, on the other hand, know that it is always going to be a MenuItem so
you can cast it as such.
Dim oMenuItem As MenuItem = DirectCast (sender, MenuItem)
Now, with oMenuItem, you can use '.' to your heart's content. Except, that
is, if you want the Name property of the MenuItem. Why? Because while you can
set the Name when you Design your menu on the Form, the MenuItem 'control'
doesn't <have> a Name. Why? I don't know. But the Control class, which most
controls inherit from, is the one that provides the Name property. And
MenuItem doesn't inherit from Control.
How important is it that you have the actual name of the MenuItem ? Ie.
what do you want to do with it?
Regards,
Fergus How important is it that you have the actual name of the MenuItem ?
Ie. what do you want to do with it?
Actually I just wrote the example. In my actual program the menu is very
(very very very ) big comprising of more than 300 options in different
menus, sub-menus. So when I was designing the Menus I designed by giving
name like M1, M2, M3, M4......... N1, N2, N3....................... These
are Menu Name. The Menu Names (what we call caption in VB 6.0) are very big
like "PREVIOUS ENTRY", "FILE PRINT".... so I thought I should write coding
based upon the menu names.
That's why I want to know how to access the menu name in the code.
In VB 6.0 we have two properties
(1) menuname.name
(2) menuname.caption
Hi Don,
Very ^ 4 = 300. Oh yes, that's big!
You can still use the MenuItem name in code, you just can't use its name
as text.
Private Sub Menu_Click (...) Handles _
M1.Click, M2.Click, M3.Click, M4.Click
If sender Is M1 Then _
MsgBox ("It's M1")
If sender Is M2 Then _
MsgBox ("It's M2")
etc
But I'm thinking that that may not do the trick. What is you that you
actually want to achieve?
Regards,
Fergus
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in
news:eA*************@tk2msftngp13.phx.gbl: The second thing I want to ask is that why is that when we type SENDER and the type dot (.) it doesn't show properties or methods associated with the sender. However, still we can type TEXT. How would we
Make sure you have Option Strict On. Then when you cast sender to a
menuitem (or other object depending on the event), you should see all the
properties of the correct type when you type the dot.
Chris
Hi Don, try this:
Private Sub OnMenuClick(...) Handles ...
Dim miMenu As MenuItem = DirectCast(sender, MenuItem)
Select Case True
Case Is M1
' M1
Case Is M2
' M2
End Select
End Sub
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflection Master "
==== Converting to 2002 ====
Remove inline declarations
"I_AM_DON_AND_YOU?" <us**@domain.com> wrote in message
news:eA*************@tk2msftngp13.phx.gbl... I have a Menu with 5 Menus as:
Menu Name Menu Text M1 File M2 Edit M3 View M4 Insert
I want to execute the code depending upon which menu is clicked. Since
most of the code is same therefore, I want to write the one procedure.
Therefore I tried to write something like...
Private Sub Menu_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _ M1.Click, M2.Click, M3.Click, M4.Click
****************** ***************** *************
x = sender.text msgbox (x)
******** End Sub
When I click the message box shows the Text property of menu i.e. if I
click M1 it shows "File", if I click M2 it shows "Edit" etc. However, I want to show Name i.e. when I click M1 it should show M1, when I click M2 it
should show M2, and so on.
The second thing I want to ask is that why is that when we type SENDER and the type dot (.) it doesn't show properties or methods associated with the sender. However, still we can type TEXT. How would we know what other methods or properties are associated with SENDER OBJECT.
Thanks in advance!
Hi Tom,
How does that one work?
Regards,
Fergus
Magic. You need to pretend that I've casted "True" to sender. ;-) (Nice one
Fergus)
Correction:
' ///
Select Case True
Case sender Is M1
' M1
Case sender Is M2
' M2
End Select
' ///
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
" System.Reflection Master "
==== Converting to 2002 ====
Remove inline declarations
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:#o**************@TK2MSFTNGP11.phx.gbl... Hi Tom,
How does that one work?
Regards, Fergus
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: zapazap |
last post by:
Dear Snake Charming Gurus,
(Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html)
First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond
for your earlier help...
|
by: Marc |
last post by:
Hi
I have a system wide hook that detects menus with class(#32768).
Is it possible to detect if a menu is a sub-menu of another?
I currently have the handle(HWND) to the menu I am interested...
|
by: Chris45 |
last post by:
Hi ,
Trying to get a menu working for sometime now have wasted money on stupid
software etc.Now have been trying out a freebee from www.dynamicdrive.com,
but have one or two question. It's...
|
by: MP Multimedia |
last post by:
Hello everyone, I need help.
I'm using a hierarchical menu made in javascript.
When I used it in a one frame page, it came out fine. But now I need to change my page to 3 frames: a top frame,...
|
by: Rob McLennan - ZETLAND |
last post by:
Hi,
I have set up an external stylesheet, named "print.css", to format the
style of all pages printed from my company's website. I've been
previewing my changes to the stylesheet by doing...
| |
by: Mark Preston |
last post by:
Its perhaps a bit early to ask, since I'm still doing the page design
and haven't got down to the coding yet, but I wonder if anyone can help
with a bit of a question. To lay the groundwork, a...
|
by: Aaron Queenan |
last post by:
How can I use the designer to add a context menu to a class which inherits
from a control, e.g. treeview, without adding the context menu to a form?
For example, to add a context menu with...
|
by: Sisnaz |
last post by:
I'm working with 2005 Beta 2 and I'm sure this is a trivial question but for
the life of me I can't figure out.
I placed a menu navigation componet on my master page and defined the
navigation...
|
by: sk |
last post by:
Hi everyone, I'm kind of new to C programming, so I thought that a
newsgroup would be the best place to ask a question about this.
I'm trying to write a small program that displays a menu and has...
|
by: Preeti |
last post by:
Hi all
I am a fresher and have been given a requirement in VB.net
I have to make an application in VB.net which will run as a system
tray icon and
will add one or two items in the default...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |