State Button

  • Thread starter Thread starter Mathieu Chavoutier
  • Start date Start date
M

Mathieu Chavoutier

Hi.

Is it possible to do a State Button ? (state selected, and state not
selected)
I want to do a choice : for example male/female yes/no.
So, if the user select Yes, no will be not selected, and Yes will be
selected.

Is there a simple way ? Have I miss something in the Button property ?

Thanks
 
Hi Mathieu,

Well, you can use a textbox, and set the Appearance to Button, or use a
boolean flag that you switch when the a button is clicked.

In either case, you will need to change the text of the button yourself.

private bool yes = true;

private void button1_Click(object sender, System.EventArgs e)
{
yes = !yes;
if(yes)
button1.Text = "Yes";
else
button1.Text = "No";
}

private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
if(checkBox1.Checked)
checkBox1.Text = "Yes";
else
checkBox1.Text = "No";
}


Happy coding!
Morten Wennevik [C# MVP]
 
Why not use a radio button inside a panel/groupbox, you can even set the
appearance of the radio button to appear as a button and can even
include images

-Benny
 
"Morten Wennevik" <[email protected]> a écrit dans le message de Hi Mathieu,

Well, you can use a textbox, and set the Appearance to Button, or use a
boolean flag that you switch when the a button is clicked.

In either case, you will need to change the text of the button yourself.

I didn't though to do only one button, and to change its state.
It is a good idea, but, my program will be used by people who don't even
have to
know what is a computer. So, if they can't see that there are a lots of
solution under their
eyes, it will be to hard for them. My objectiv if to do a really simple
program to use.

But, thank you, I will try to keep this idea for another program :o).
 
Benny Mathew said:
Why not use a radio button inside a panel/groupbox, you can even set the
appearance of the radio button to appear as a button and can even
include images

I will try is now, and see what I can do with it, thanks.
I stay on this news group for next question :o)
 
Mathieu Chavoutier said:
I will try is now, and see what I can do with it, thanks.
I stay on this news group for next question :o)

Well, that's what I was looking for, thank you :o)
 
I have a problem :

I have 5 RadioButtons on the same panel.
How can I do to say that "if I click on THAT button, you must not remove the
checked value of THOSE buttons" ?

For example, I have the questions :
are you :Male/female
are you sure ? yes/no

If I am a male, I am sure of it. So, if I click on yes, I still have to stay
a man :o)
(it is a really stupid example, but at least, it explain really well my
problem :o)))

For the moment, either I am not sure to be a man, or I am sure of nothing !

Help :o)
 
Mathieu Chavoutier said:
I have a problem :

I have 5 RadioButtons on the same panel.
How can I do to say that "if I click on THAT button, you must not remove the
checked value of THOSE buttons" ?

For example, I have the questions :
are you :Male/female
are you sure ? yes/no

If I am a male, I am sure of it. So, if I click on yes, I still have to stay
a man :o)
(it is a really stupid example, but at least, it explain really well my
problem :o)))

For the moment, either I am not sure to be a man, or I am sure of nothing
!

AutoCheck = false;
 
Hi Mathieu,

To prevent the user from editing values that should not be changed when certain radiobutton choices are selected etc, disable those controls. So, if the user clicks on THAT button, disable THOSE buttons so the user can't uncheck them.

A simple MessageBox should do the trick for a yes/no question

if(MessageBox.Show("Are you sure?", "Validate", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
// user selected yes
}
else
{
// user selected no
}


Happy coding!
Morten Wennevik [C# MVP]
 
Morten Wennevik said:
Hi Mathieu,

To prevent the user from editing values that should not be changed when
certain radiobutton choices are selected etc, disable those controls. So,
if the user clicks on THAT button, disable THOSE buttons so the user can't
uncheck them.
A simple MessageBox should do the trick for a yes/no question

In fact the question I have to ask are not linked.
But, I have found myButton.Autockeck, whom can disable the auto ckeck :o)

Thanks you.
 
Back
Top