我知道如何动态地将项目(复选框)添加到工具条,但我想添加一个存在于表单中的复选框。我试过使用代码
Dim chkboxhost As ToolStripControlHost
chkboxhost = New ToolStripControlHost(CheckBox1)
toolStrip1.Items.Add(chkboxhost)
但这使得已经存在的复选框,转到屏幕的左上角,当工具条被点击时,它就会出现。所以我想将复选框添加到菜单中,而不是转到左上角,有什么想法吗?
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.