like a COMPLETE idiot.
So i figured you guys with some experience could help me out.
I need to see the simple code for a basic windows form-app that
Contains 2 simple things
A checkbox, and a text-window of some sort.
When i check the box, a text appears in the textbox.
if i figure that out i know where to start.
what im trying to do is a simple program for our seller at the office, he always manages
to get about a third of the info from the customer that we on the productionfloor need to know.
So i figured if i make a simple app that he can have running when he has the customer on the phone
he can just check boxes and text appears -every box should have a certain text assigned to it.
that way the text that appears can be used when creating an orderform for us on the floor.
we work with printing and putting logos on clothes and similar.
Something like this: (linked to a picture)
Could someone please make a simple code and post so i can get started? i seem to have hit a dead end here hehe.
Thanks
Anthony ClarkePosted Jan 14, 2011, 5:14 AM
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
textBox1.Text = "The Check Box is Checked";
else
if (checkBox1.Checked == false)
textBox1.Text = "";
Sam HobbsPosted Jan 14, 2011, 10:29 PM
What happens if you need to find all orders with a specific operation, such as all orders for logos on the left chest. If your orders are saved somewhere such as a database then you would need a program to read all orders and look in the text for the words left chest. It seems unlikely you will need to do that but it is just an example. A better way is to store a code; a numberr or something that is more efficient and more conducive to use by software. Then that could make the program easier to use for finding orders with a specific operation. You could have a lookup capability that could look up the text for printing the text in the order and elsewhere.
theLizardPosted Jan 14, 2011, 5:24 PM
The pro's and con's over one method or the other is simply how much code you want to write especially if you have a large number of check boxes but certainly what Anthony showed is more readable.
Something else to consider is how many check boxes will you have and will the number change based on what production item is being ordered?
For multiple check boxes you could be writing a mountain of code to do what you want, better to have a generic function to handle all the check boxes.
Something like this will handle hundreds of check boxes...
private void genericCheckedChanged(object sender, EventArgs e)
{
CheckBox ch = (CheckBox)sender;
textbox1.Text += ch.Checked == true ? getCheckBoxText(ch.Tag) : "" + ", "; //each check box has a Tag property, give a numeric value 1, 2, 3, 4, 5, 6
}
public string getCheckBoxText(object tag)
{
int which = null;
string text = null;
int.TryParse(tag.ToString(), out which);
switch(which)
{
case 1:
text = "Upper left chest"
break;
case 2:
text = "Upper right chest"
break;
case 3:
text = "Upper middle chest"
break;
}
return(text);
}
This would make your whole system dynamic and allow you to (with modification) load text from a file, csv, xml or database.
Edit:
You will also need to deal with the possibility that a check box has been checked when it should not have been so when it is clicked a second time the text box will need to reflect that change.
You can do this by having a method that reads the checked state of all check boxes in a for loop using the controls collection.
Jonas HammarPosted Jan 14, 2011, 4:39 PM
Anthony ClarkePosted Jan 14, 2011, 3:51 PM
Jonas HammarPosted Jan 14, 2011, 3:46 PM
Anthony ClarkePosted Jan 14, 2011, 3:42 PM
Yeah, although in the end, without feeding the method parameters it still works out to the same amount of code. Your best using the way i did before you go onto the more complex method of Lizard, but as Lizard says, it is more flexible as you can feed multiple parameters in to the function and still give it a result.
e.g. if (getSingleSided == True);
{
\\blah
}
else
{
\\blah
}
theLizardPosted Jan 14, 2011, 3:34 PM
this one line
textbox1.Text = checkbox1.Checked == true? "Is Checked" : "Un Checked";
is the equivalence to ALL of this
if (checkBox1.Checked == true)
textBox1.Text = "The Check Box is Checked";
else
if (checkBox1.Checked == false)
textBox1.Text = "";
Jonas HammarPosted Jan 14, 2011, 3:27 PM
Anthony ClarkePosted Jan 14, 2011, 2:47 PM
In regards to your other question can you mark my original answer as correct then we will proceed further.
Thanks
Anthony
Jonas HammarPosted Jan 14, 2011, 2:09 PM
theLizardPosted Jan 12, 2011, 5:34 PM
If your descriptions are static for each text box this will do what you want without too much work but has the potential to be more flexible if you need it to be
private void checkbox1_CheckedChanged(object sender, EventArgs e)
{
textbox1.Text = checkbox1.Checked ? "Is Checked" : "Un Checked";
}
eg.
textbox1.Text = checkbox1.Checked ? getSingleSided() : getDoubleSided();
In this case you could get other information from a method / function before assigning the text values depending on checked state.