I created a simple code here just to play around with C#. It has 3 buttons and 1 panel. If you click on the 2nd & 3rd button the panel height changes. Is that also possible to change the color?
For example, if I click on the 2nd button, I would like to have it as yellow and at the same time the height changes as well, and the same with 3rd button.
public partial class Form1 : Form
{
public int heightPanel;
public Form1()
{
InitializeComponent();
heightPanel = panel1.Height;
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Height = heightPanel;
}
private void button2_Click(object sender, EventArgs e)
{
panel1.Height = this.Height/2;
}
private void button3_Click(object sender, EventArgs e)
{
panel1.Height = this.Height - 150;
}
}
I have an idea but I don’t know where to put this. I think it would be something like this:
panel1.Height=this.BackColor.ToString();
Any inputs?
Response to reply
Yes, I would like to retain the 3 colors if I click in any of the button. I’m not sure if it’s possible. For ex:
my button1 =pink
button2=yellow
button3=green
If I click on the button 1 I’ll see the pink color, and if I click on the button2 I’ll see the pink and yellow.
Is that possible?
All you’d need to do would be to set the
BackColoron a new line. For instance…