سؤال

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#?

هل كانت مفيدة؟

المحلول

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 new MainForm
  • Added four ToolStripButton items and gave them images to make them easier to see.
  • Set the CheckOnClick property to True for each of them
  • Set the Checked property of toolStripButton1 to True;
  • 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):

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

نصائح أخرى

If have placed this code in the preceding control in the 'Leave' event.

    Private Sub PurposeComboBox_Leave(sender As Object, e As EventArgs) Handles PurposeComboBox.Leave

    Me.AppliancesForSelectedFunctionToolStripButton.PerformClick()

    End Sub

I do not know if you could place code in Form Load or not. Hope this helps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top