Toolstripmenu add item
I know h开发者_高级运维ow to add a item(checkbox) to a toolstrip dynamically, but I want to add a checkbox which is exists in a form. I've tried using the code
Dim chkboxhost As ToolStripControlHost
chkboxhost = New ToolStripControlHost(CheckBox1)
toolStrip1.Items.Add(chkboxhost)
but this makes the already existing checkbox, go to the top left of screen and when the toolstrip is click it appears. So I want to add the checkbox to the menu, without going to top left corner, any ideas ?
BlueRaja's response is the answer, you could do it several ways, here's two:
Firstly:
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
ToolStripButton2.Checked = ToolStripButton1.Checked
'Do whatever you want with your buttons
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
ToolStripButton1.Checked = ToolStripButton2.Checked
'Do whatever you want with your buttons
End Sub
Another approach:
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
'Do whatever you want with your buttons
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
'Do whatever you want with your buttons
End Sub
Private Sub ToolStripButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.CheckedChanged
ToolStripButton2.Checked = ToolStripButton1.Checked
End Sub
Private Sub ToolStripButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.CheckedChanged
ToolStripButton1.Checked = ToolStripButton2.Checked
End Sub
I prefer the first one obviously.
精彩评论