Posted by : Sudhir Chekuri Wednesday, 17 February 2016

Used to group collection of controls.

Panel is not visible in the output but helps in design time to group collection of controls.
All the controls inside panel can be moved at once and they can be relatively arranged inside a panel.

Steps to use a panel

Drag and drop a panel
Add controls inside it.
Arrange them relatively inside the panel.
Now you can arrange the panel in a form which brings all the controls inside it without any change in their relative distances of controls inside it.

Default event: Paint which fired when the panel is drawn/created on the form. This event is fired after form load event.

Code to make change the back color of panel when it is painted or created
private void panel1_Paint(object sender, PaintEventArgs e)
        {
           panel1.BackColor = Color.Black;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            panel1.BackColor = Color.Yellow;
        }
First panel back color will be yellow and then it is changed to black when it is created.

Code to change visibility of panel on button click
private void button1_Click(object sender, EventArgs e)
        {
            if (panel1.Visible == true)
            {
                panel1.Visible = false;
            }
            else { panel1.Visible = true; }
        }

All the controls inside the panel will be visible and invisible to the user based on the visibility of the panel in which they are present.

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -