ToolStripButton.CheckOnClick Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur nilai yang menunjukkan apakah ToolStripButton seharusnya muncul secara otomatis ditekan dan tidak ditekan saat diklik.
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
Nilai Properti
true
ToolStripButton jika akan muncul secara otomatis ditekan dan tidak ditekan saat diklik; jika tidak, false
. Default adalah false
.
Contoh
Contoh kode berikut mengatur CheckOnClick properti ke true
dan menggunakan Checked properti dalam peristiwa CheckedChanged untuk mengubah font teks tombol menjadi tebal saat tombol diklik.
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