Hi
I created a simple code here just to play C# around. 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.
Thanks :-)

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?

Thanks

>panel1.Height=this.BackColor.ToString();
I'm not entirely sure what you hoped this would do, but if you want to change the color of the panel, you need to change the BackColor property. For example:

panel1.BackColor = Color.Yellow;

And this is a separate statement from changing the height.

>panel1.Height=this.BackColor.ToString();
I'm not entirely sure what you hoped this would do, but if you want to change the color of the panel, you need to change the BackColor property. For example:

panel1.BackColor = Color.Yellow;

And this is a separate statement from changing the height.

Thanks Narue, this one works. But I would like to retain the color of the button2 and button3. Not sure if that's possible.
So that means, for example I set the color in button2 as blue and in button3 as green. If I click on button2 I get blue and if I click on the button3 I get the blue and green. Is that possible?

>But I would like to retain the color of the button2 and button3.
Do the same thing, except on button2/button3 instead of panel1.

>But I would like to retain the color of the button2 and button3.
Do the same thing, except on button2/button3 instead of panel1.

hmm, what do you mean do the same thing?

>hmm, what do you mean do the same thing?
I'm beginning to suspect that you're not suited to the mental rigors of programming. :icon_rolleyes:

Remember when I showed you how to change the BackColor of the panel? Here, I'll show you again in case you forgot:

panel1.BackColor = Color.Yellow;

Instead of panel1, type button2 and see what happens. All of these things are derived from a base class called Control, and Control is where the BackColor property comes from. What that means is you can set the BackColor property for any object derived from Control and it will magically do the "same thing".

commented: Constructive criticism with style, while being helpful. You can't ask for much more than that. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.