I have made a toolbar with some buttons inside in c# and I am trying to make these button remain pressed while I first click on the and unpressed during my second click on them.
Any suggestion?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted May 1, 2011, 6:30 AM EDT
Michael Ommer10 reputationPosted May 1, 2011, 11:35 AM EDT
FroglegRank #1,020 · 1.9K reputationPosted May 1, 2011, 1:08 PM EDT
public partial class Form1 : Form
{
bool bttnclicked = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
toolStripButton1.BackColor = Color.Green;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (!bttnclicked)
{
toolStripButton1.BackColor = Color.Red;
bttnclicked = true;
}
else
{
toolStripButton1.BackColor = Color.Green;
bttnclicked =false;
}
}
}
Abhimanyu K VatsaRank #14 · 51.7K reputationPosted May 2, 2011, 4:09 AM EDT
if you want to change the button appearence then you have to use some another method from outside.
for this use two images, one looks like pressed button and another like released button (up). and then use if...else condition in code-behind to switch between them.
hope this helps