ToolStripButton.Checked 屬性

定義

取得或設定值,指出已按下或未按下 ToolStripButton

public:
 property bool Checked { bool get(); void set(bool value); };
public bool Checked { get; set; }
member this.Checked : bool with get, set
Public Property Checked As Boolean

屬性值

如果已按下或未按下 ToolStripButton,則為 true,否則為 false。 預設為 false

範例

下列程式碼範例會將 CheckOnClick 屬性設定為 true ,並在事件中使用 CheckedCheckedChanged 屬性,在按一下按鈕時,將按鈕文字的字型變更為粗體。

ToolStripButton^ boldButton;

void InitializeBoldButton()
{
    boldButton = gcnew ToolStripButton;
    boldButton->Text = "B";
    boldButton->CheckOnClick = true;
    boldButton->CheckedChanged  += gcnew EventHandler(this, 
        &Form1::boldButtonCheckedChanged);
    toolStrip1->Items->Add(boldButton);
}

void boldButtonCheckedChanged(Object^ sender, EventArgs^ e)
{
    if (boldButton->Checked)
    { 
        this->Font= gcnew System::Drawing::Font(this->Font, 
            FontStyle::Bold);
    }
    else
    { 
        this->Font = gcnew System::Drawing::Font(this->Font, 
            FontStyle::Regular);
    }
}


//   internal:
internal ToolStripButton boldButton;

private void InitializeBoldButton()
{
    boldButton = new ToolStripButton();
    boldButton.Text = "B";
    boldButton.CheckOnClick = true;
    toolStrip1.Items.Add(boldButton);
}

private void boldButton_CheckedChanged(object sender, EventArgs e)
{
    if (boldButton.Checked)
    {
        this.Font = new Font(this.Font, FontStyle.Bold);
    }
    else
    {
        this.Font = new Font(this.Font, FontStyle.Regular);
    }
}
Friend WithEvents boldButton As ToolStripButton

Private Sub InitializeBoldButton()
    boldButton = New ToolStripButton()
    boldButton.Text = "B"
    boldButton.CheckOnClick = True
    toolStrip1.Items.Add(boldButton)

End Sub

Private Sub boldButton_CheckedChanged(ByVal sender As [Object], _
    ByVal e As EventArgs) Handles boldButton.CheckedChanged
    If boldButton.Checked Then
        Me.Font = New Font(Me.Font, FontStyle.Bold)
    Else
        Me.Font = New Font(Me.Font, FontStyle.Regular)
    End If

End Sub

適用於