Results 1 to 2 of 2

Thread: ContextMenuStrip in runtime help ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: ContextMenuStrip in runtime help ?

    this works:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim newTextBox1 As New TextBox
    5.         newTextBox1.Text = "test" 'MySplit(1)
    6.         newTextBox1.Multiline = True
    7.         newTextBox1.Location = New Point(150, 80)
    8.         Dim newContextMenuStrip1 As New ContextMenuStrip
    9.         Dim tsi As ToolStripItem = newContextMenuStrip1.Items.Add("Display", Nothing, AddressOf menuClicked)
    10.         tsi.Tag = newTextBox1
    11.         newTextBox1.ContextMenuStrip = newContextMenuStrip1
    12.         Me.Controls.Add(newTextBox1)
    13.         Me.Controls.Add(newContextMenuStrip1)
    14.     End Sub
    15.  
    16.     Private Sub menuClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
    17.         MsgBox(DirectCast(DirectCast(sender, ToolStripMenuItem).Tag, TextBox).Text)
    18.     End Sub
    19.  
    20. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width