Set the ToolStripButton.CheckOnClick
property to True
. (It's found in the Behavior
section of the Items Collection Editor
.)
This makes clicking it just like toggling the Down
property in a Delphi TSpeedButton
(making it flat or depressed), and if ToolStripButton1.Checked
is the equivalent of if SpeedButton1.Down
in Delphi.
To set up the test, I did the following:
- Created a new Winforms application
- Dropped a
ToolStrip
onto the newMainForm
- Added four
ToolStripButton
items and gave them images to make them easier to see. - Set the
CheckOnClick
property toTrue
for each of them - Set the
Checked
property oftoolStripButton1
toTrue
; Added the code below to
toolStripButton1.Click
method MainForm.toolStripButton1_Click(sender: System.Object; e: System.EventArgs); begin toolStripButton2.Checked := not toolStripButton2.Checked; toolStripButton4.Checked := toolStripButton2.Checked; end;
Running the app (initial startup, toolStripButton1
checked and the others unchecked):
The first button is clearly down, and the rest are up.
After clicking toolStripButton1
once:
The first button is now up (unchecked) and the second and fourth are down (checked). (I should pay more attention to the consistency in sizing if I do successive images in future posts.)