- Joined
- Jul 1, 2010
- Messages
- 1,254
- Reaction score
- 359
Hello!
In programming this is one of the difficult coding I have yet to master.
I have made a (mini) program that contains textboxes and a button.
Works like when you write a number and then press the button it should change the color of that many textboxes.. example:
The code is written to make this manually... But how would I code this into a loop or something like that?
My current code:
Would really appriciate help for this one.. I have tried to look into loops & such.. Couldn't figure it out :/
And as I said at the top.. Loops and try's & do has been the hardest part of me to understand fully (Still learning to code )
~Xakzi
In programming this is one of the difficult coding I have yet to master.
I have made a (mini) program that contains textboxes and a button.
Works like when you write a number and then press the button it should change the color of that many textboxes.. example:
The code is written to make this manually... But how would I code this into a loop or something like that?
My current code:
Code:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "1")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.Visible = false;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
}
else if (textBox1.Text == "2")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.Visible = false;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
}
else if (textBox1.Text == "3")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.BackColor = Color.DarkRed;
textBox4.Visible = true;
textBox5.Visible = false;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
}
else if (textBox1.Text == "4")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.BackColor = Color.DarkRed;
textBox4.Visible = true;
textBox5.BackColor = Color.DarkRed;
textBox5.Visible = true;
textBox6.Visible = false;
textBox7.Visible = false;
textBox8.Visible = false;
}
else if (textBox1.Text == "5")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.BackColor = Color.DarkRed;
textBox4.Visible = true;
textBox5.BackColor = Color.DarkRed;
textBox5.Visible = true;
textBox6.BackColor = Color.DarkRed;
textBox6.Visible = true;
textBox7.Visible = false;
textBox8.Visible = false;
}
else if (textBox1.Text == "6")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.BackColor = Color.DarkRed;
textBox4.Visible = true;
textBox5.BackColor = Color.DarkRed;
textBox5.Visible = true;
textBox6.BackColor = Color.DarkRed;
textBox6.Visible = true;
textBox7.BackColor = Color.DarkRed;
textBox7.Visible = true;
textBox8.Visible = false;
}
else if (textBox1.Text == "7")
{
textBox2.BackColor = Color.DarkRed;
textBox2.Visible = true;
textBox3.BackColor = Color.DarkRed;
textBox3.Visible = true;
textBox4.BackColor = Color.DarkRed;
textBox4.Visible = true;
textBox5.BackColor = Color.DarkRed;
textBox5.Visible = true;
textBox6.BackColor = Color.DarkRed;
textBox6.Visible = true;
textBox7.BackColor = Color.DarkRed;
textBox7.Visible = true;
textBox8.BackColor = Color.DarkRed;
textBox8.Visible = true;
}
else
{
MessageBox.Show("Please choose a number between 1 to 7!!");
}
Would really appriciate help for this one.. I have tried to look into loops & such.. Couldn't figure it out :/
And as I said at the top.. Loops and try's & do has been the hardest part of me to understand fully (Still learning to code )
~Xakzi
Attachments
You must be registered for see attachments list