Simple Collapse Panel in windows forms

No.of Views2638
Bookmarked0 times
Downloads 
Votes0
By  vinothnat   On  15 Feb 2010 22:02:37
Tag : CSharp , Windows Forms
Simple Collapse Panel in windows forms
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 
Introduction

Collapse Panel is a usercontrol for using the collapsible panel. There is no more control for collapsing the content in a panel. This ScrollablePanel control allows you to scrolling the contents which are in a panel. We can see the magic of this control by downloading the demo project which is attached with this article.

Prerequisite

1. .NET Framework 2.0

2. Visual Studio 2005


Description

I have created a 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.

Implementation

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

{codecitation class="brush: c#; gutter: false;" width="500px"}

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;
}

{/codecitation}


The above code is used to animate the collapse functionality. Here the ScrollIntervalValue variable is assigned from the property value of ScrollInterval. Here the top height value also gets by HeaderHeight property.


How incorporate/use in user project

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.


Conclusion

Hence we can use this collapse panel control to collapse the contents in a panel. We can set the background image or backcolor or what ever is possible to a panel. It is very useful when we doing this kind of collapse contents with panel.


Thank you
Vinoth

 
Sign Up to vote for this article
 
About Author
 
vinothnat
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-03 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top