Click here to Skip to main content
15,884,629 members
Articles / Desktop Programming / Windows Forms

Collapsible GroupBox With Icon

Rate me:
Please Sign up or sign in to vote.
2.40/5 (4 votes)
18 May 2009CPOL3 min read 47.6K   719   17   9
A collapsible GroupBox with icon support.

CollapsedGrpBxWithIcon.JPG

Introduction

This GroupBox collapses and supports using multiple icons including embedded icons for each condition, either full size or collapsed. This is my first article on CodeProject, and I felt that with all of the wonderful contributors on this site providing examples of how to, that now it is my turn to give a small contribution.

This project was born from two projects that are on CodeProject:

With out these two authors, this article and this project would not exist. I will refer any arrangements of licensing back to the license as posted by them. Please read both of their articles and you will get a very good understanding of what is going on in the code. I do not feel that it should be repeated here - after all, I would simply be explaining what they have already explained. Besides, it would take the fun out of seeing what was actually done, and might also remove the learning, and since learning is the purpose here, that would not be a good thing.

Background

As I read the articles, I found that both had overridden the OnPaint method, but one thing lacked in the CollapsibleGroupBox which was that it could have a null icon image, or simply only one icon image: a plus or a minus. I wanted something that I could add more pizazz to. Fancy icons for full sized, collapsed, or even mouse over, mouse down etc.. I have embedded the icons as part of the resources so that they are easily packaged as standard icons. Although you can also add them through the property manager in Visual Studio, they have their defaults. This is one short coming you will need to fix - I always default - if you want icon only and no text, or no icon and text only, that is up to you to supply the properties and the logic to disable or enable text/icons on the GroupBox. In reality, this could even be made into an image across the top and not just an icon, making the control much fancier.

Using the code

The code in this article is in C#. If you want it in VB NET, please use one of the free online converters and let it teach you about C# and or VB.NET. That is how I learned C#. Sorry I am not a spoon feeder.

In order to use the attached code, you must create a new project file called CollapsibleGroupBox. Then, add the two code files to the project, and additionally, add a resources file named resources with the embedded icons aptly named plus, minus, and standard. Compile the project. Add the Custom Control to your toolbox and then drag to a Form - you should be good to go.

Points of interest

I learned a little bit about the OnPaint method, the Rectangle method, and also about getting objects from embedded resources. It was fun to modify the original code and combine what I felt was the best of the two GroupBoxes into one, just a little niftier.

History

This is the first release. When I get more time, I will try to release the whole project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Still learning everyday, lots of talent out there teaches me how ..like a borg I have adapted...

Comments and Discussions

 
QuestionNot working in .NET 2008 Pin
killerbranch1-Aug-10 2:44
killerbranch1-Aug-10 2:44 
AnswerRe: Not working in .NET 2008 Pin
stixoffire5-Oct-10 20:15
stixoffire5-Oct-10 20:15 
GeneralMy vote of 1 Pin
Xmen Real 1-Jun-10 15:40
professional Xmen Real 1-Jun-10 15:40 
GeneralRe: My vote of 1 Pin
stixoffire5-Oct-10 20:00
stixoffire5-Oct-10 20:00 
GeneralRe: My vote of 1 Pin
Xmen Real 6-Oct-10 1:41
professional Xmen Real 6-Oct-10 1:41 
GeneralRe: My vote of 1 Pin
stixoffire6-Oct-10 5:46
stixoffire6-Oct-10 5:46 
GeneralRe: My vote of 1 Pin
Xmen Real 6-Oct-10 5:53
professional Xmen Real 6-Oct-10 5:53 
GeneralMy vote of 1 Pin
sjaustin29-May-09 21:16
sjaustin29-May-09 21:16 
AnswerRe: My vote of 1 Pin
stixoffire5-Oct-10 19:53
stixoffire5-Oct-10 19:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.