Collapsible group box

Source: Internet
Author: User
Tags addgroup

This article from http://www.codeproject.com/KB/miscctrl/CollapsibleGroupBox.aspx

    • Download project version 1.2-59.5 KB

Introduction

I am working on a project that needs to display groups/containers of Editable data (data not just for display), and I came up with the idea for this library of controls. I looked into usingPropertygridControl but it didn't have the elegance I was looking for, so here are the fruits of my labor.

Background

Years ago, I worked on a project for the Macintosh using Symantec's tcl (think class library, not Tcl/tk ). TCL has a view and pane architecture where one wocould create a pane containing controls (or anything for that matter) and add the panes toCscroller. While searching codeproject for something suitable, I came monitoring SS rollup control and 3D Studio MAX like s0000able dialogbar, but both are written in C ++/MFC, and my project is in C #.

Using the code

After opening your C # windows application solution, openForm, Right-click in the toolbox, and select the "Add/Remove items... "menu item. after the "customize toolbox" dialog comes up, select the "Browse... "button, and navigate to\ Collapsiblegroupbox_1_2 \ bin \ releaseDirectory, and selectUitoolbox. dll. If you navigate to the "My User Controls" group in the toolbox, you will notice that several items have been added.

Go back to the Solution Explorer, right-click on your project, and select the menu itemAdd \ add new item. Select a user control and edit its code. Change the base class fromSystem. Windows.FormSToUitoolbox. collapsiblegroupbox, Save it, and then switch back to its design view.

At this point, you shoshould see something that looks like the following:

Feel free to resize it and add some controls.

Go back toFormYou wish to addExpandingpanelTo (in the design view), and addExpandingpanel(From the "My User Controls" group of the Toolbox), And You shoshould see something like this:

Switch toForm'S code and add supporting code to addCollapsiblegroupboxToExpandingpanel:

Collapse | Copy code
  Public   form  1 () {  //       //     required for Windows  form  designer support     //     initializecomponent ();   //      usercontrol  1 is a collapsiblegroupbox   expandingpanel1.addgroup ( New   usercontrol  1 () ;}

That's it. You're ready to build and run it now. The controls automatically take care of collapsing, expanding, deleting themselves, and scrolling.

Points of interest

If you want eCollapsiblegroupbox. CS, You will notice that although it contains a control for the collapse button and a control for the trash can button, it doesn't containGroupboxControl. Instead, it 'fakes' a group box and draws it itself. Why? The first draft usedGroupboxControl, and everything seemed to work fine. That is, until I created a panel derived fromExpandingpanel, Added some controls, and then built it. when the project was built, the derived panel seemed to 'eat' the controls. it turns out that the bug had to do with the embedded group box and the ownership of the controls, so nowCollapsiblegroupboxDraws the group box itself.

Known issues
  • Fonts-I 've only used the default 8.25pt Microsoft sans serif with the controls. It _ shoshould _ work correctly with any font, but it usesGraphics. measurestring ()To get the width, and I 've noticedMeasurestring ()Doesn' t always work correctly.
  • ExpandingpanelS andCollapsiblegroupboxEs are sometimes missing-ifFormContainsExpandingpanelOrCollapsiblegroupboxControl, I 've noticed that sometimes they disappear the next time I open the project. A workaround that I 've found that usually works is to closeForm(BOTH designer and code) and then reopen it. I haven't figured out why, but this seems to fix the problem.
  • Trash can Layout-when playing withCaptionAndContainstrashcanProperties ofCollapsiblegroupbox, I 've noticed that the trash can icon doesn' t always appear in the correct position. Usually building the project solves this.
Future enhancements

Here are some potential enhancements I may make in the future:

Drag & Drop: It wocould be cool ifExpandingpanelSupported drag and drop and allowed you to D & D withinExpandingpanelTo resort its items, or D & D to moveCollapsiblegroupboxFrom oneExpandingpanelTo another. The UI wocould look something like this:

Add panes insteadCollapsiblegroupboxES: for my project, I only needed group boxes, but for a more general purpose, I might changeExpandingpanelTo add a more generic type (pane ?) :

Collapse | Copy code
Public ClassPane: system. Windows.FormS.Usercontrol{...}Public ClassCollapsiblegroupbox: pane {...}Public ClassExpandingpanel: system. Windows.FormS. Panel {...Public VoidAddgroup (uitoolbox. pane thepane ){...}...}
FAQ
    • I wowould like to modify and use your code. Are there any restrictions I need to know about, or can I just build on your code at will?

      You may use and modify the original code to your needs, free of charge, provided:

      • I have Ed credit in the products 'about box (something along the lines of "collapsible group box by Jeff beeghly ").
      • (Optional) I receive a fully licensed copy of the product (regardless of whether the product is free, shrinkwrap, or commercial ).

      You may not:

      • Parse the code (just the code, not as part of an application ).
      • "Re-brand" the Code as your own.
      • Publicly release modified versions of the code or publicly release Works derived from the code without express written authorization.
History
    • 25th June, 2004, 1.0

      • Initial Release
    • 3rd January, 2006, 1.2
      • Built with Visual Studio. NET 2003.
      • Added monkfinger's fix for resizing (see message board ).
      • Added Doug case's request to programmatically setGroupboxTo a collapsed State.
      • Removed commented code fromCollapsiblegroupbox. CS.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.