ToolBarButton.Style 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置工具栏按钮的样式。
public:
property System::Windows::Forms::ToolBarButtonStyle Style { System::Windows::Forms::ToolBarButtonStyle get(); void set(System::Windows::Forms::ToolBarButtonStyle value); };
public System.Windows.Forms.ToolBarButtonStyle Style { get; set; }
member this.Style : System.Windows.Forms.ToolBarButtonStyle with get, set
Public Property Style As ToolBarButtonStyle
属性值
ToolBarButtonStyle 值之一。 默认值为 ToolBarButtonStyle.PushButton
。
例外
分配的值不是 ToolBarButtonStyle 值之一。
示例
下面的代码示例创建一个和三ToolBarButton个ToolBar控件,将按钮分配给工具栏,并设置一些按钮的常用属性。 此代码要求已创建 aMenuItem、 ImageListToolTip a 和 aForm,并且ImageList至少为其分配了一个Image。
public:
void InitializeMyToolBar()
{
// Create the ToolBar, ToolBarButton controls, and menus.
ToolBarButton^ toolBarButton1 = gcnew ToolBarButton( "Open" );
ToolBarButton^ toolBarButton2 = gcnew ToolBarButton;
ToolBarButton^ toolBarButton3 = gcnew ToolBarButton;
ToolBar^ toolBar1 = gcnew ToolBar;
MenuItem^ menuItem1 = gcnew MenuItem( "Print" );
array<MenuItem^>^ temp1 = {menuItem1};
System::Windows::Forms::ContextMenu^ contextMenu1 =
gcnew System::Windows::Forms::ContextMenu( temp1 );
// Add the ToolBarButton controls to the ToolBar.
toolBar1->Buttons->Add( toolBarButton1 );
toolBar1->Buttons->Add( toolBarButton2 );
toolBar1->Buttons->Add( toolBarButton3 );
// Assign an ImageList to the ToolBar and show ToolTips.
toolBar1->ImageList = imageList1;
toolBar1->ShowToolTips = true;
/* Assign ImageIndex, ContextMenu, Text, ToolTip, and
Style properties of the ToolBarButton controls. */
toolBarButton2->Style = ToolBarButtonStyle::Separator;
toolBarButton3->Text = "Print";
toolBarButton3->Style = ToolBarButtonStyle::DropDownButton;
toolBarButton3->ToolTipText = "Print";
toolBarButton3->ImageIndex = 0;
toolBarButton3->DropDownMenu = contextMenu1;
// Add the ToolBar to a form.
Controls->Add( toolBar1 );
}
public void InitializeMyToolBar()
{
// Create the ToolBar, ToolBarButton controls, and menus.
ToolBarButton toolBarButton1 = new ToolBarButton("Open");
ToolBarButton toolBarButton2 = new ToolBarButton();
ToolBarButton toolBarButton3 = new ToolBarButton();
ToolBar toolBar1 = new ToolBar();
MenuItem menuItem1 = new MenuItem("Print");
ContextMenu contextMenu1 = new ContextMenu(new MenuItem[]{menuItem1});
// Add the ToolBarButton controls to the ToolBar.
toolBar1.Buttons.Add(toolBarButton1);
toolBar1.Buttons.Add(toolBarButton2);
toolBar1.Buttons.Add(toolBarButton3);
// Assign an ImageList to the ToolBar and show ToolTips.
toolBar1.ImageList = imageList1;
toolBar1.ShowToolTips = true;
/* Assign ImageIndex, ContextMenu, Text, ToolTip, and
Style properties of the ToolBarButton controls. */
toolBarButton2.Style = ToolBarButtonStyle.Separator;
toolBarButton3.Text = "Print";
toolBarButton3.Style = ToolBarButtonStyle.DropDownButton;
toolBarButton3.ToolTipText = "Print";
toolBarButton3.ImageIndex = 0;
toolBarButton3.DropDownMenu = contextMenu1;
// Add the ToolBar to a form.
Controls.Add(toolBar1);
}
Public Sub InitializeMyToolBar()
' Create the ToolBar, ToolBarButton controls, and menus.
Dim toolBarButton1 As New ToolBarButton("Open")
Dim toolBarButton2 As New ToolBarButton()
Dim toolBarButton3 As New ToolBarButton()
Dim toolBar1 As New ToolBar()
Dim menuItem1 As New MenuItem("Print")
Dim contextMenu1 As New ContextMenu(New MenuItem(){menuItem1})
' Add the ToolBarButton controls to the ToolBar.
toolBar1.Buttons.Add(toolBarButton1)
toolBar1.Buttons.Add(toolBarButton2)
toolBar1.Buttons.Add(toolBarButton3)
' Assign an ImageList to the ToolBar and show ToolTips.
toolBar1.ImageList = imageList1
toolBar1.ShowToolTips = True
' Assign ImageIndex, ContextMenu, Text, ToolTip, and
' Style properties of the ToolBarButton controls.
toolBarButton2.Style = ToolBarButtonStyle.Separator
toolBarButton3.Text = "Print"
toolBarButton3.Style = ToolBarButtonStyle.DropDownButton
toolBarButton3.ToolTipText = "Print"
toolBarButton3.ImageIndex = 0
toolBarButton3.DropDownMenu = contextMenu1
' Add the ToolBar to a form.
Controls.Add(toolBar1)
End Sub
注解
如果按钮 Style 设置为 DropDownButton 可以指定 MenuItem 在按下下拉按钮时要显示的按钮。 如果样式设置为 ToolBarButtonStyle.Separator
,工具栏按钮显示为按钮分隔符,而不是按钮。 该 ToolBarButtonStyle.ToggleButton
样式会导致工具栏按钮像切换按钮一样操作;它可以处于打开或关闭状态。