Simple Collapse Panel - Windows application in C#

Hi all, There is no option to collapsing functionality in panel control.

I have created a panel control with up/down arrow images. We can collapse this control by clicking those arrows. There are some property values allowing us the interval of collapsing time. The ScrollInterval value is used to set the interval time for collapsing animation. And the HeaderHeight property value is set to be the height of header part in this control. I just used some calculation to set the height value for this control in a certain loop. This much of calculation makes some animation to collapsing the control.

You can see the magic of this control by downloading the demo project which is available to download here.

The simple calculation of control’s height is possible to collapse the control. Just see the following code,

if (this.Height > this.lblTop.Height)
{
while (this.Height > this.lblTop.Height)
{
Application.DoEvents();
this.Height -= ScrollIntervalValue;
}
this.lblTop.ImageIndex = 1;
this.Height = this.lblTop.Height;
}
else if (this.Height == this.lblTop.Height)
{
int x = this.FixedHeight;
while (this.Height <= (x))
{
Application.DoEvents();
this.Height += ScrollIntervalValue;
}
this.lblTop.ImageIndex = 0;
this.Height = x;
}

Just refer the control in your application, and add the control in your form. Then set the property values of this control ScrollInterval and HeaderHeight as you want. If you don’t set those property values it might be taken by default values. Now build your project and run. By clicking the arrow images in collapse panel, you can see the magic.

For More…see my article in code project.

http://www.codeproject.com/KB/cs/CollapsePanel.aspx

...S.VinothkumaR.


No comments: