|
-
Dec 19th, 2009, 10:59 PM
#1
Thread Starter
Lively Member
Get the Name of the Active Control
Hi i was wondering how to get the name of the active control in Visual basic
system.reflection..... that doesnt work
like i use addhandler so if I do that it gets me the name of the adress of the original control
Also, I'm trying to get a toolstripdropdown menu as a bookmarks thing; how can I get the name of the selected dropdown item?
thanks guys
its a big confusing but please ask if i'm not clear I didn't get any help for my other 3 questions
-
Dec 19th, 2009, 11:28 PM
#2
Re: Get the Name of the Active Control
Why exactly do you need the name of the active control? I would think that you would want the active control itself, which you would get from the form's ActiveControl property. If you really do want its name then you can just get its Name property.
That said, I think what you're actually asking for is the control that raised the event you're currently handling. In that case you use the 'sender' parameter. Again, you don't need the name because the 'sender' refers to the object itself. That goes for menu items that are all covered by the same Click event handler too. The 'sender' parameter refers to the menu item that was clicked.
-
Dec 19th, 2009, 11:39 PM
#3
Thread Starter
Lively Member
Re: Get the Name of the Active Control
k i have a dropdown menu in a toolstrip and I want users to add items into it, and when an item is clicked, it will go to whatever the clicked item's text is
thats my main problem i cant find the script that identifies the control
in a normal listbox and combobox its selecteditem
but i'm using a toostripdropdown menu button
-
Dec 20th, 2009, 12:06 AM
#4
Re: Get the Name of the Active Control
Like I said, you can use a single method to handle the Click event for all the menu items. This is such a common occurrence that there are methods dedicated to it specifically. In that one event handler, the 'sender' parameter refers to the menu item that was clicked.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.ItemsToolStripMenuItem.DropDownItems.Add(Me.TextBox1.Text, _ Nothing, _ AddressOf HandleMenuItemClick) End Sub Private Sub HandleMenuItemClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim item = DirectCast(sender, ToolStripMenuItem) MessageBox.Show(item.Text) End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|