How to add ToolStrip menu items programmatically?
Asked
Active
Viewed 3,806 times
0
-
2MSDN 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 Answers
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
-
The OP was looking for menu items, not buttons in a ToolStripControlHost. – LarsTech Feb 18 '14 at 15:28
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