How to add ContextMenuStrip at runtime in Vb.Net

By James J

Add ContextMenuStrip in button click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ContextMenu As New ContextMenuStrip()
        
Me.ContextMenuStrip = ContextMenu

        
Dim FirstTooltip As New ToolStripMenuItem()
        
Dim SecondTooltip As New ToolStripMenuItem()
        
Dim ThirdTooltip As New ToolStripMenuItem()

        FirstTooltip.
Text = "&First Item"
        SecondTooltip.
Text = "&Second Item"
        ThirdTooltip.
Text = "&Third Item"

      
ContextMenu.Items.Add(FirstTooltip)
      
ContextMenu.Items.Add(SecondTooltip)
      
ContextMenu.Items.Add(ThirdTooltip)
End Sub

> See below image

How to add ContextMenuStrip at runtime in Vb.Net  (2558 Views)