ToolStripButton.CheckOnClick 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得或設定一個值,指示點擊時是否 ToolStripButton 應該自動顯示為按下或未按下。
public:
property bool CheckOnClick { bool get(); void set(bool value); };
public bool CheckOnClick { get; set; }
member this.CheckOnClick : bool with get, set
Public Property CheckOnClick As Boolean
屬性值
true 如果點擊時 ToolStripButton 應該自動顯示為按下而非按下;否則, false。 預設值為 false。
範例
以下程式碼範例將屬性CheckOnClick設定為 ,true並在事件中CheckedChanged利用該Checked屬性在按鈕點擊時將字體改為粗體。
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