Reputation: 39
I'm very new at windows forms' programming. Currently, this is only an idea of a program, but let me write down a simple flow of the program:
So to say, there's content1 and content2 both existing in the combo boxes and both radio buttons. I have no problem linking both functions, however... I have some trouble printing the text. So to say, if I choose content1, this following string will appear on the text box :
"Chosen content is : content1"
For the checkboxes - list box relationship, I have color1, color2, and color3. More than 1 colors can be chosen (checked, if it's a check box), and after choosing, this following string will also appear under the content selection text previously stated :
"Chosen content is : content1" "Chosen colors are : color1 color2"
How do I make the text formats appear? So far I'm using this code and I can't display the text in the text box yet. Text box's name is textBoxResults.
if (radioContent1.Checked == true)
{
textBoxResults.Text = "Chosen content is : content1";
}
Also, conceptually, how do I link the color1 to 3's checkboxes so if I check one or more boxes so that it will correspond to one or more choices chosen in the color1 to 3's contents in the list box control?
Thank you in advance for the answers. This will help me understand Windows Forms a bit more.
Upvotes: 0
Views: 57
Reputation: 19641
The following is just a basic idea to get you started, it can, however, be enhanced in different ways.
In your Form Load event, add the following code:
radioButton1.CheckedChanged += RadioButtons_CheckedChanged;
radioButton2.CheckedChanged += RadioButtons_CheckedChanged;
radioButton3.CheckedChanged += RadioButtons_CheckedChanged;
Then you can use the RadioButtons_CheckedChanged
event handler to change the text accordingly:
private void RadioButtons_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
textBox1.Text = "Chosen content is Content1.";
else if (radioButton2.Checked)
textBox1.Text = "Chosen content is Content2.";
else if (radioButton3.Checked)
textBox1.Text = "Chosen content is Content3.";
}
Similarly, for CheckBoxes:
checkBox1.CheckedChanged += CheckBoxes_CheckedChanged;
checkBox2.CheckedChanged += CheckBoxes_CheckedChanged;
checkBox3.CheckedChanged += CheckBoxes_CheckedChanged;
Then:
private void CheckBoxes_CheckedChanged(object sender, EventArgs e)
{
if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
{
textBox2.Clear();
return;
}
textBox2.Text = "Chosen colors are :";
if (checkBox1.Checked)
textBox2.Text += " color1";
if (checkBox2.Checked)
textBox2.Text += " color2";
if (checkBox3.Checked)
textBox2.Text += " color3";
}
Upvotes: 1