[Part2]C# - Checkboxes (Windows Form)

04/27/2010 12:20 ©Hyperlink#1
Part 2 - Checkboxes
Okay now you have learned about buttons and textboxes at basics.

What is checkboxes used for?
A checkbox is used to check for more choices.
You can use it for making vote buttons, using them instead putting 100Buttons or anything else.
Checkboxes are pretty cool to use in a windows form application.

Now we are gonna look at checkboxes.
First you have to make 2 checkboxes.
One with the Text "Yes" and the other with the Text "No".
(Think back to Button, how to change text)
No create a button and make text "My Choice is?".
Then double click on the button.
Now we will need to make 3 checks for it.
One for first checkbox.
One for second checkbox.
One for that both is checked.
One for that nothing is checked.

Okay so far.
Now how do we make the checks?.
Simply create one:
Code:
if (checkBox1.Checked == true)
{
MessageBox.Show("You have choosed yes.");
}
and then 3 more else could be like this:
Code:
else if (checkBox2.Checked == true)
{
MessageBox.Show("You have choosed No.");
}
else if (checkBox1.Checked == true && checkBox2.Checked == true)
{
MessageBox.Show("You have choosed both.");
}
else
{
MessageBox.Show("Please make a choice");
}
}
Now it will checks for what you have checked.
Congratulations you have now created a checkbox.
You can try combine it with Part 1.

Other controls with checkbox/radiobuttons, thanks to DarkMessiah:
Quote:
Originally Posted by DarkMessiah
you can use
Code:
if(checkBox1.Checked)
{
     //do stuff
}
will make it more efficient.

also, it will never reach the "both checked" state since you used if/else's.

radio buttons in a panel to do yes/no or true/false option choices.
in Part 3 we will look at creating a text creator
Like notepad.

[Only registered and activated users can see links. Click Here To Register...]

Any problems post a reply or send me a PM.
04/27/2010 14:35 s.bat#2
Shouldn't this be moved to [Only registered and activated users can see links. Click Here To Register...] for closer topic alignment?
04/27/2010 19:05 ©Hyperlink#3
maybe, i dont know :)
I just thought here, since other programming tutorials are here and the other forums are just only german speak x.x
04/27/2010 22:15 Matic^#4
Really nice and understandable tutorial, keep it up ;)
04/27/2010 22:29 DarkMessiah#5
Quote:
Originally Posted by ©Hyperlink View Post
...
you can use
Code:
if(checkBox1.Checked)
{
     //do stuff
}
will make it more efficient.

also, it will never reach the "both checked" state since you used if/else's.

radio buttons in a panel to do yes/no or true/false option choices.
04/27/2010 23:51 ©Hyperlink#6
Quote:
Originally Posted by DarkMessiah View Post
you can use
Code:
if(checkBox1.Checked)
{
     //do stuff
}
will make it more efficient.

also, it will never reach the "both checked" state since you used if/else's.

radio buttons in a panel to do yes/no or true/false option choices.
I will add that to tutorial :)