如何以编程方式添加ToolStrip菜单项?
答案 0 :(得分:1)
这是代码...... 用于添加非工具条默认控件.. Dim StripHost1作为新的ToolStripControlHost(button1) ToolStrip1.Items.Add(StripHost1)
用于添加工具条菜单项(默认值,在设计时也允许)..
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})
答案 1 :(得分:1)
以下对我有用,因为我想要的是实现工具条生成的文本。
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