Context Menu....

OK, so I have a context menu that contains two options - a TextBox and a (Submit) option...it pops up when a user right clicks a radio button on my form. I want the user to be able to enter a string in the textbox, click the (Submit) option, and have the string replace the current text of the radio button.

It works easy for one Radio Button, but I'd like to have this functionality available for several components. Aside from creating a separate context menue for each component (very time and space consuming), is there any way to refer to the object from which the context menu came from when writing the (Submit) option's code, so that I can do the same thing with only one Context Menu?

(hope that made sense...)

[726 byte] By [East] at [2007-12-16]
# 1
Hi,
In your contextMenu Click event:

Me.ActiveControl.Text = toolStripTextBox1.Text

cheers,
Paul June A. Domag

PaulDomag at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
I gave that a shot, but it still doesn't always work -- its possible to right click on an option that doesn't have the focus at the time, triggering the context menu. The option that has the focus is changed, even though it's not the one which triggered the context menu....
any other suggestions, plz?
East at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
The ContextMenuStrip has a SourceControl property that is supposed to return the control on which the menu was raised. The documentation is incomplete and the property is Nothing when I test it, so my guess is that it is incomplete at this stage. Until this property is properly implemented, I suggest you set a class-level variable using the sender in the MouseDown event handler.
jmcilhinney at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
I tried this, and it worked just fine for me. When you call the show() you have to pass on the control that's called it.



Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.Click
ContextMenuStrip1.Show(CheckBox1, CheckBox1.Width, 10)
End Sub

Private
Sub ContextMenuStrip1_Opened(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenuStrip1.Opened
MsgBox(ContextMenuStrip1.SourceControl.Name)
End Sub

Dustin.

Dustin_H at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
When I tested it I just set the ContextMenuStrip property of the control. I would have expected that that would have set the SourceControl property of the menu when right-clicking a control, but apparently not.
jmcilhinney at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...