これは私の方法です。それはちらつきのない、そして - 私は思う - 少し柔軟です。あなたはトグルボタン(オン/オフオプション)として使用したいToolStripMenuItemsのセットを持っている場合は
は、これを試してみてください。
(ctxWildCards
は、ファイルの種類に基づいてフィルタを選択するために使用される、ちょうど私のContextMenuStrip
です - 検索またはFileDialogsの場合)
これはVisual Basic(明らかに!)であるため、Handlersをプログラムで追加するか、 'Handles ...'節を使用して追加することができます。
Private Sub OnOffToolStripMenuItem_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
Dim t = TryCast(sender, ToolStripMenuItem)
If Not t Is Nothing Then
'Since you may have more On/off-Items, check to see if the Owner is the ContextMenuStrip
If t.Owner Is ctxWildCards Then
' The ContextMenuStrip will stay open on Right-click, i.e. the user can check and close by clicking 'normally'
ctxWildCards.AutoClose = (e.Button = Windows.Forms.MouseButtons.Left)
End If
'Just me using a custom image for checked items.
t.Checked = Not t.Checked
t.Image = If(t.Checked, rdoImage, Nothing)
End If
End Sub
' On leaving ToolStripMenuItems of the ContextMenuStrip, allow it to AutoClose
Private Sub OnOffToolStripMenuItem_MouseLeave(sender As System.Object, e As System.EventArgs)
ctxWildCards.AutoClose = True
End Sub
-1あなたがコーディングしている言語ではない答えと、グローバル変数を使用するように提案した答えを選択しましたか? もっと関連する回答があります。 –