2011-01-07 51 views
0

我知道如何將一個項目(複選框)動態添加到工具條,但是我想添加一個存在於表單中的複選框。我使用的代碼Toolstripmenu添加項目

Dim chkboxhost As ToolStripControlHost 
chkboxhost = New ToolStripControlHost(CheckBox1) 
toolStrip1.Items.Add(chkboxhost) 

試過但是這使得現有的複選框,轉到屏幕的左上角時,工具條是點擊它出現。所以我想將複選框添加到菜單中,而不是去左上角,有什麼想法?

+0

通常這是通過一個`ToolStripMenuItem`來完成的,它設置了`CheckOnClick = true`。這不符合你的需求嗎? – 2011-01-07 23:37:43

回答

0

BlueRaja的回答就是答案,你可以這樣做多種方式,這裏有二:

首先:

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 

另一種方法:

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 

我喜歡顯然是第一個。