次の方法で共有


ToolBarButton.Style プロパティ

ツール バー ボタンのスタイルを取得または設定します。

Public Property Style As ToolBarButtonStyle
[C#]
public ToolBarButtonStyle Style {get; set;}
[C++]
public: __property ToolBarButtonStyle get_Style();public: __property void set_Style(ToolBarButtonStyle);
[JScript]
public function get Style() : ToolBarButtonStyle;public function set Style(ToolBarButtonStyle);

プロパティ値

ToolBarButtonStyle 値の 1 つ。既定値は ToolBarButtonStyle.PushButton です。

例外

例外の種類 条件
InvalidEnumArgumentException 代入された値が、 ToolBarButtonStyle 値の 1 つではありません。

解説

ボタンの StyleDropDownButton に設定されている場合は、ドロップダウン ボタンを押すと MenuItem が表示されるように指定できます。スタイルが ToolBarButtonStyle.Separator に設定されているツール バー ボタンは、ボタンではなく、ボタンの区切り記号として表示されます。 ToolBarButtonStyle.ToggleButton スタイルを指定すると、ツール バー ボタンはトグル ボタンのように機能し、オンとオフの状態を切り替えることができます。

使用例

[Visual Basic, C#, C++] ToolBar と 3 つの ToolBarButton コントロールを作成し、ボタンをツール バーに割り当ててから、ボタンの共通プロパティの一部を設定する例を次に示します。このコードは、 MenuItemImageListToolTip 、および Form が作成されていることと、 ImageList に少なくとも 1 つの Image が割り当てられていることを前提にしています。

 
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


[C#] 
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);
 }
 

[C++] 
public:
void InitializeMyToolBar()
 {
    // Create the ToolBar, ToolBarButton controls, and menus.
    ToolBarButton* toolBarButton1 = new ToolBarButton(S"Open");
    ToolBarButton* toolBarButton2 = new ToolBarButton();
    ToolBarButton* toolBarButton3 = new ToolBarButton();
    ToolBar* toolBar1 = new ToolBar();
    MenuItem* menuItem1 = new MenuItem(S"Print");

    MenuItem* temp1 [] = {menuItem1};
    System::Windows::Forms::ContextMenu* contextMenu1 = new 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 = S"Print";
    toolBarButton3->Style = ToolBarButtonStyle::DropDownButton;
    toolBarButton3->ToolTipText = S"Print";
    toolBarButton3->ImageIndex = 0;
    toolBarButton3->DropDownMenu = contextMenu1;
 
    // Add the ToolBar to a form.
    Controls->Add(toolBar1);
 }
 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

ToolBarButton クラス | ToolBarButton メンバ | System.Windows.Forms 名前空間 | ToolBarButtonStyle