0

How to add ToolStrip menu items programmatically?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Argon
  • 221
  • 5
  • 14
  • 2
    MSDN How to: Add ToolStrip Items Dynamically: http://msdn.microsoft.com/en-us/library/ms229625(v=vs.110).aspx – Matt Wilko Feb 18 '14 at 15:16

2 Answers2

1

here is the code... for adding non-toolstrip default controls.. Dim StripHost1 As New ToolStripControlHost(button1) ToolStrip1.Items.Add(StripHost1)

for adding toolstrip menu items (defaults, allowed at design time also)..

Friend WithEvents myToolStripButton As System.Windows.Forms.ToolStripButton
Me.myToolStripButton = New System.Windows.Forms.ToolStripButton
Me.MainToolStrip.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.myToolStripButton})
Sarvesh Mishra
  • 2,014
  • 15
  • 30
1

The following worked for me as all I wanted was to achieve a toolstrip generated text.

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    Dim NEOitem As String = TextBox6.Text
    ContextMenuStrip1.Items.Add(NEOitem)
End Sub
Argon
  • 221
  • 5
  • 14