checkeddelphi-prismtoolstripbuttonoxygene

How to programmatically press toolstripbutton down?


I want to push toolstripbutton down in my code and I can't seem to be able to do that. I know on Delphi RAD Studio or XE, you can do the following and cause the button to be pressed.

ToolStripButton1.Down := true;

The only ToolStripButton property I see that comes close to "down" is checked true or false. If I do set it to true, it only highlights the toolstripbutton not press it down.

Here is how the button looks when I put my mouse on it and click:

enter image description here

You can clearly see that the Zoom In button is down.

Here is how the button looks when I try to do the samething through my code by setting CheckOnClick true and Checked true.

enter image description here

In this image, the only thing you can see is the blue box around it. I suppose if I had used just the text on the button, you will see that the whole button filled with blue color to show that it was pressed.

enter image description here

I also have toolstrip button in my other program which acts the same way but I had to use imagelist control to switch between pressed or down or checked verses not pressed or down or checked.

So, is there a way to press the ToolStripButton programmatically in Delphi Prism or C#?


Solution

  • 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:

    Running the app (initial startup, toolStripButton1 checked and the others unchecked):

    One button down

    The first button is clearly down, and the rest are up.

    After clicking toolStripButton1 once:

    Two buttons down

    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.)