Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I press a button I want it to stay in pressed state untill I'll press the button again.
How can I do it in C#?

Thanks!
Posted

If you're using Windows Forms, you can use a CheckBox with the Appearance property set to Button.

Nick
 
Share this answer
 
It works!
I used a CheckBox with the Appearance property set to Button and it's exactly what I wanted.
But why the size of the button is so small?
I can not change the height and the weight of the button? Why?
 
Share this answer
 
What is that you want to achieve using this? If you want to toggle something there can be ways to do it.

If it's about showing the button pressed... you can do that too using css or javascript. Something like, Click once button control, it will be pressed as long as response is not recieved. Now in your case, what is the logic of keeping it pressed?
 
Share this answer
 
And what you want to have on the "button"? I used it in toolStripMenu. If I set size, no change. But when I set size and image on the button, it has size, which I want and shows full image.
C#
CheckBox bold = new CheckBox();
bold.Appearance = Appearance.Button;
bold.Size = new Size(16,16);
bold.Image = Properties.Resources.b;

Where image from Resources has size 16x16px.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900