ContextMenuStrip in runtime help ?
Hi, im trying to work with adding controls in runtime.
Anyways ive added a ContextMenuStrip control in runtime and added a item called "Display". The ContextMenuStrip is also added to textbox's that are also added in runtime and when i right click a textbox i see the "Display" but i want it to do "msgbox(textbox.text)" when i click "Display".
Like it will msgbox whatever is in that textbox.
So how do i add it to the code for runtime ?
Code:
Dim newContextMenuStrip1 As New ContextMenuStrip
newContextMenuStrip1.Items.Add("Display")
Dim newTextBox1 As New TextBox
newTextBox1.Text = MySplit(1)
newTextBox1.Multiline = True
newTextBox1.Size = New Point(150, 80)
newTextBox1.ContextMenuStrip = newContextMenuStrip1
Thanks for any help
Re: ContextMenuStrip in runtime help ?
this works:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim newTextBox1 As New TextBox
newTextBox1.Text = "test" 'MySplit(1)
newTextBox1.Multiline = True
newTextBox1.Location = New Point(150, 80)
Dim newContextMenuStrip1 As New ContextMenuStrip
Dim tsi As ToolStripItem = newContextMenuStrip1.Items.Add("Display", Nothing, AddressOf menuClicked)
tsi.Tag = newTextBox1
newTextBox1.ContextMenuStrip = newContextMenuStrip1
Me.Controls.Add(newTextBox1)
Me.Controls.Add(newContextMenuStrip1)
End Sub
Private Sub menuClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(DirectCast(DirectCast(sender, ToolStripMenuItem).Tag, TextBox).Text)
End Sub
End Class