ToolStripDropDownButton 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表一個控制項,點擊時會顯示一個關聯 ToolStripDropDown 的選項,使用者可從中選擇單一項目。
public ref class ToolStripDropDownButton : System::Windows::Forms::ToolStripDropDownItem
[System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.StatusStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripDropDownButton : System.Windows.Forms.ToolStripDropDownItem
[<System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.StatusStrip | System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)>]
type ToolStripDropDownButton = class
inherit ToolStripDropDownItem
Public Class ToolStripDropDownButton
Inherits ToolStripDropDownItem
- 繼承
- 繼承
-
ToolStripDropDownButton
- 衍生
- 屬性
範例
以下程式碼範例在點擊 時ToolStripDropDownButton顯示三個ToolStripButton控制項。 按鈕會改變表單的前景顏色。
// Declare the drop-down button and the items it will contain.
ToolStripDropDownButton^ dropDownButton1;
ToolStripDropDown^ dropDown;
ToolStripButton^ buttonRed;
ToolStripButton^ buttonBlue;
ToolStripButton^ buttonYellow;
void InitializeDropDownButton()
{
dropDownButton1 = gcnew ToolStripDropDownButton;
dropDown = gcnew ToolStripDropDown;
dropDownButton1->Text = "A";
// Set the drop-down on the DropDownButton.
dropDownButton1->DropDown = dropDown;
// Declare three buttons, set their forecolor and text,
// and add the buttons to the drop-down.
buttonRed = gcnew ToolStripButton;
buttonRed->ForeColor = Color::Red;
buttonRed->Text = "A";
buttonBlue = gcnew ToolStripButton;
buttonBlue->ForeColor = Color::Blue;
buttonBlue->Text = "A";
buttonYellow = gcnew ToolStripButton;
buttonYellow->ForeColor = Color::Yellow;
buttonYellow->Text = "A";
buttonBlue->Click += gcnew EventHandler(this,
&Form1::colorButtonsClick);
buttonRed->Click += gcnew EventHandler(this,
&Form1::colorButtonsClick);
buttonYellow->Click += gcnew EventHandler(this,
&Form1::colorButtonsClick);
array<ToolStripItem^>^ ToolStrips =
{buttonRed,buttonBlue,buttonYellow};
dropDown->Items->AddRange(ToolStrips);
toolStrip1->Items->Add(dropDownButton1);
}
// Handle the buttons' click event by setting the forecolor
// of the form to the forecolor of the button that is clicked.
void colorButtonsClick(Object^ sender, EventArgs^ e)
{
ToolStripButton^ senderButton = (ToolStripButton^) sender;
this->ForeColor = senderButton->ForeColor;
}
// internal:
// Declare the drop-down button and the items it will contain.
internal ToolStripDropDownButton dropDownButton1;
internal ToolStripDropDown dropDown;
internal ToolStripButton buttonRed;
internal ToolStripButton buttonBlue;
internal ToolStripButton buttonYellow;
private void InitializeDropDownButton()
{
dropDownButton1 = new ToolStripDropDownButton();
dropDown = new ToolStripDropDown();
dropDownButton1.Text = "A";
// Set the drop-down on the ToolStripDropDownButton.
dropDownButton1.DropDown = dropDown;
// Set the drop-down direction.
dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Left;
// Do not show a drop-down arrow.
dropDownButton1.ShowDropDownArrow = false;
// Declare three buttons, set their foreground color and text,
// and add the buttons to the drop-down.
buttonRed = new ToolStripButton();
buttonRed.ForeColor = Color.Red;
buttonRed.Text = "A";
buttonBlue = new ToolStripButton();
buttonBlue.ForeColor = Color.Blue;
buttonBlue.Text = "A";
buttonYellow = new ToolStripButton();
buttonYellow.ForeColor = Color.Yellow;
buttonYellow.Text = "A";
buttonBlue.Click += new EventHandler(colorButtonsClick);
buttonRed.Click += new EventHandler(colorButtonsClick);
buttonYellow.Click += new EventHandler(colorButtonsClick);
dropDown.Items.AddRange(new ToolStripItem[]
{ buttonRed, buttonBlue, buttonYellow });
toolStrip1.Items.Add(dropDownButton1);
}
// Handle the buttons' click event by setting the foreground color of the
// form to the foreground color of the button that is clicked.
private void colorButtonsClick(object sender, EventArgs e)
{
ToolStripButton senderButton = (ToolStripButton)sender;
this.ForeColor = senderButton.ForeColor;
}
' Declare the drop-down button and the items it will contain.
Friend WithEvents dropDownButton1 As ToolStripDropDownButton
Friend WithEvents dropDown As ToolStripDropDown
Friend WithEvents buttonRed As ToolStripButton
Friend WithEvents buttonBlue As ToolStripButton
Friend WithEvents buttonYellow As ToolStripButton
Private Sub InitializeDropDownButton()
dropDownButton1 = New ToolStripDropDownButton()
dropDown = New ToolStripDropDown()
dropDownButton1.Text = "A"
' Set the drop-down on the ToolStripDropDownButton.
dropDownButton1.DropDown = dropDown
' Set the drop-down direction.
dropDownButton1.DropDownDirection = ToolStripDropDownDirection.Left
' Do not show a drop-down arrow.
dropDownButton1.ShowDropDownArrow = False
' Declare three buttons, set their foreground color and text,
' and add the buttons to the drop-down.
buttonRed = New ToolStripButton()
buttonRed.ForeColor = Color.Red
buttonRed.Text = "A"
buttonBlue = New ToolStripButton()
buttonBlue.ForeColor = Color.Blue
buttonBlue.Text = "A"
buttonYellow = New ToolStripButton()
buttonYellow.ForeColor = Color.Yellow
buttonYellow.Text = "A"
dropDown.Items.AddRange(New ToolStripItem() {buttonRed, buttonBlue, buttonYellow})
toolStrip1.Items.Add(dropDownButton1)
End Sub
' Handle the buttons' click event by setting the foreground color of the
' form to the foreground color of the button that is clicked.
Public Sub colorButtonsClick(ByVal sender As [Object], ByVal e As EventArgs) _
Handles buttonRed.Click, buttonBlue.Click, buttonYellow.Click
Dim senderButton As ToolStripButton = CType(sender, ToolStripButton)
Me.ForeColor = senderButton.ForeColor
End Sub
備註
ToolStripDropDownButton 看起來像 ToolStripButton,但使用者點擊時會顯示一個下拉選單區域。 透過設定 ShowDropDownArrow 屬性來隱藏或顯示下拉箭頭。 ToolStripDropDownButton 主機 A ToolStripOverflowButton 顯示溢出的 ToolStrip項目。
使用這些 ToolStripDropDownButton 工具來啟動熟悉的下拉選單控制,例如顏色選擇器。 將屬性設 ShowDropDownArrow 為 , true 以更清楚地告訴使用者下拉選單中還有更多選項可用。
建構函式
| 名稱 | Description |
|---|---|
| ToolStripDropDownButton() |
初始化 ToolStripDropDownButton 類別的新執行個體。 |
| ToolStripDropDownButton(Image) |
初始化一個新的類別實例 ToolStripDropDownButton ,顯示指定的影像。 |
| ToolStripDropDownButton(String, Image, EventHandler, String) |
初始化一個擁有指定名稱的類別新實例ToolStripDropDownButton,顯示指定的文字與圖片,並提出事件。 |
| ToolStripDropDownButton(String, Image, EventHandler) |
初始化一個新的類別實例 ToolStripDropDownButton ,顯示指定的文字與圖片並引發 |
| ToolStripDropDownButton(String, Image, ToolStripItem[]) |
初始化 ToolStripDropDownButton 類別的新執行個體。 |
| ToolStripDropDownButton(String, Image) |
初始化一個新的類別實例 ToolStripDropDownButton ,顯示指定的文字與圖片。 |
| ToolStripDropDownButton(String) |
初始化顯示指定文字的類別新實例 ToolStripDropDownButton 。 |
屬性
方法
事件
明確介面實作
| 名稱 | Description |
|---|---|
| IDropTarget.OnDragDrop(DragEventArgs) |
引發 DragDrop 事件。 (繼承來源 ToolStripItem) |
| IDropTarget.OnDragEnter(DragEventArgs) |
引發 DragEnter 事件。 (繼承來源 ToolStripItem) |
| IDropTarget.OnDragLeave(EventArgs) |
引發 DragLeave 事件。 (繼承來源 ToolStripItem) |
| IDropTarget.OnDragOver(DragEventArgs) |
引發 |