ToolStripButton.CheckOnClick Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value indicating whether the ToolStripButton should automatically appear pressed in and not pressed in when clicked.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool CheckOnClick { get; set; }

Property Value

Type: System.Boolean

true if the ToolStripButton should automatically appear pressed in and not pressed in when clicked; otherwise, false. The default is false.

The following code example sets the CheckOnClick property to true and uses the Checked property in a CheckedChanged event to change the font of the button text to bold when the button is clicked.

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);
	}

}

.NET Framework
Available since 2.0
Return to top
Show: