0

ツールストリップに項目 (チェックボックス) を動的に追加する方法は知っていますが、フォームに存在するチェックボックスを追加したいと考えています。コードを使ってみました

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

ただし、これにより既存のチェックボックスが作成され、画面の左上に移動し、ツールストリップをクリックすると表示されます。それで、左上隅に移動せずにメニューにチェックボックスを追加したいのですが、何かアイデアはありますか?

4

1 に答える 1

0

BlueRajaの応答が答えです、あなたはそれをいくつかの方法で行うことができます、ここに2つあります:

まず:

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

私は明らかに最初のものを好みます。

于 2011-08-02T01:48:04.593 に答える