ToolStripDropDownMenu.ShowCheckMargin 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否在 ToolStripMenuItem 的左边缘显示选中标记的位置。
public:
property bool ShowCheckMargin { bool get(); void set(bool value); };
public bool ShowCheckMargin { get; set; }
member this.ShowCheckMargin : bool with get, set
Public Property ShowCheckMargin As Boolean
属性值
如果显示选中标记位置,则为 true
;否则为 false
。 默认值为 false
。
示例
下面的代码示例演示如何通过设置复选和图像边距来创建和初始化 ContextMenuStrip 控件。 有关完整代码列表,请参阅 如何:在 ContextMenuStrip 控件中启用检查边距和图像边距。
public Form5()
{
// Size the form to show three wide menu items.
this.Width = 500;
this.Text = "ToolStripContextMenuStrip: Image and Check Margins";
// Create a new MenuStrip control.
MenuStrip ms = new MenuStrip();
// Create the ToolStripMenuItems for the MenuStrip control.
ToolStripMenuItem bothMargins = new ToolStripMenuItem("BothMargins");
ToolStripMenuItem imageMarginOnly = new ToolStripMenuItem("ImageMargin");
ToolStripMenuItem checkMarginOnly = new ToolStripMenuItem("CheckMargin");
ToolStripMenuItem noMargins = new ToolStripMenuItem("NoMargins");
// Customize the DropDowns menus.
// This ToolStripMenuItem has an image margin
// and a check margin.
bothMargins.DropDown = CreateCheckImageContextMenuStrip();
((ContextMenuStrip)bothMargins.DropDown).ShowImageMargin = true;
((ContextMenuStrip)bothMargins.DropDown).ShowCheckMargin = true;
// This ToolStripMenuItem has only an image margin.
imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip();
((ContextMenuStrip)imageMarginOnly.DropDown).ShowImageMargin = true;
((ContextMenuStrip)imageMarginOnly.DropDown).ShowCheckMargin = false;
// This ToolStripMenuItem has only a check margin.
checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip();
((ContextMenuStrip)checkMarginOnly.DropDown).ShowImageMargin = false;
((ContextMenuStrip)checkMarginOnly.DropDown).ShowCheckMargin = true;
// This ToolStripMenuItem has no image and no check margin.
noMargins.DropDown = CreateCheckImageContextMenuStrip();
((ContextMenuStrip)noMargins.DropDown).ShowImageMargin = false;
((ContextMenuStrip)noMargins.DropDown).ShowCheckMargin = false;
// Populate the MenuStrip control with the ToolStripMenuItems.
ms.Items.Add(bothMargins);
ms.Items.Add(imageMarginOnly);
ms.Items.Add(checkMarginOnly);
ms.Items.Add(noMargins);
// Dock the MenuStrip control to the top of the form.
ms.Dock = DockStyle.Top;
// Add the MenuStrip control to the controls collection last.
// This is important for correct placement in the z-order.
this.Controls.Add(ms);
}
Public Sub New()
' Size the form to show three wide menu items.
Me.Width = 500
Me.Text = "ToolStripContextMenuStrip: Image and Check Margins"
' Create a new MenuStrip control.
Dim ms As New MenuStrip()
' Create the ToolStripMenuItems for the MenuStrip control.
Dim bothMargins As New ToolStripMenuItem("BothMargins")
Dim imageMarginOnly As New ToolStripMenuItem("ImageMargin")
Dim checkMarginOnly As New ToolStripMenuItem("CheckMargin")
Dim noMargins As New ToolStripMenuItem("NoMargins")
' Customize the DropDowns menus.
' This ToolStripMenuItem has an image margin
' and a check margin.
bothMargins.DropDown = CreateCheckImageContextMenuStrip()
CType(bothMargins.DropDown, ContextMenuStrip).ShowImageMargin = True
CType(bothMargins.DropDown, ContextMenuStrip).ShowCheckMargin = True
' This ToolStripMenuItem has only an image margin.
imageMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = True
CType(imageMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = False
' This ToolStripMenuItem has only a check margin.
checkMarginOnly.DropDown = CreateCheckImageContextMenuStrip()
CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowImageMargin = False
CType(checkMarginOnly.DropDown, ContextMenuStrip).ShowCheckMargin = True
' This ToolStripMenuItem has no image and no check margin.
noMargins.DropDown = CreateCheckImageContextMenuStrip()
CType(noMargins.DropDown, ContextMenuStrip).ShowImageMargin = False
CType(noMargins.DropDown, ContextMenuStrip).ShowCheckMargin = False
' Populate the MenuStrip control with the ToolStripMenuItems.
ms.Items.Add(bothMargins)
ms.Items.Add(imageMarginOnly)
ms.Items.Add(checkMarginOnly)
ms.Items.Add(noMargins)
' Dock the MenuStrip control to the top of the form.
ms.Dock = DockStyle.Top
' Add the MenuStrip control to the controls collection last.
' This is important for correct placement in the z-order.
Me.Controls.Add(ms)
End Sub
注解
将 ShowCheckMargin 属性设置为 true
,以在用户选择 ToolStripMenuItem时显示复选标记。