ToolBarButton 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ToolBarButton 類別的新執行個體。
多載
ToolBarButton() |
初始化 ToolBarButton 類別的新執行個體。 |
ToolBarButton(String) |
初始化 ToolBarButton 類別的新執行個體,並顯示按鈕上指派的文字。 |
ToolBarButton()
初始化 ToolBarButton 類別的新執行個體。
public:
ToolBarButton();
public ToolBarButton ();
Public Sub New ()
範例
下列程式碼範例會建立 和 三 ToolBarButton 個 ToolBar 控制項、將按鈕指派給工具列,並設定一些按鈕的通用屬性。 此程式碼需要 MenuItem 已建立 、 ImageList ToolTip 和 Form ,且 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
備註
新建立 ToolBarButton 的 沒有預設 Text 或 Image 指派給它。 按鈕的預設樣式為 ToolBarButtonStyle.PushButton
。
另請參閱
適用於
ToolBarButton(String)
初始化 ToolBarButton 類別的新執行個體,並顯示按鈕上指派的文字。
public:
ToolBarButton(System::String ^ text);
public ToolBarButton (string text);
new System.Windows.Forms.ToolBarButton : string -> System.Windows.Forms.ToolBarButton
Public Sub New (text As String)
參數
- text
- String
要顯示在新 ToolBarButton 上的文字。
範例
下列程式碼範例會建立 和 三 ToolBarButton 個 ToolBar 控制項、將按鈕指派給工具列,並設定一些按鈕的通用屬性。 此程式碼需要 MenuItem 已建立 、 ImageList ToolTip 和 Form ,且 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
備註
新建立 ToolBarButton 的 未 Image 指派給它。 按鈕的預設樣式為 PushButton 。 參數 text
會指派給 屬性, Text 並顯示在新的工具列按鈕控制項上。