SplitContainer with maximise/minimise buttons on splitter bar?

I thought this was a good idea and wrote a class that inherits the SplitContainer and include this functionality. SplitContainerExt class is attached, add it to a project and build, then you find it in Toolbox under application components tab.

How it works: OnPaint is used to draw the icons and saves the rectangles for later reference, OnMouseUp checks the rectangles and handles the splitter position (distance) accordingly. Hovering the arrows changes the cursor, clicking them moves the splitter to either end, but respects each panels minimum size, they can be set to 0. Due to the icons used I found that the splitter had to be limited to minimum width 10, other icons or changing the one used can make a thinner splitter a viable option.
 

Attachments

  • vbnet20-SplitContainerExt.zip
    1.2 KB · Views: 421
Issue with panel size

Using a splitContainerEx is causing me an issue when I want to see min sizes for both panels.

Error message is

SplitterDistance must be between Panel1MinSize and Width - Panel2MinSize

For Example.. my panel size is 1113 x 355

with Vertical Orientation

I set Panel1MinSize = 25

and

Panel2MinSize = 500

and

SplitterDistance = 300

If I follow the formula... 300 is between 25 and 613.

Is this a bug or am I doing something wrong ?
 
This happens with the regular SplitContainer also. The reason is because the properties are serialized alphabetically to Designer-generated code (Panel1MinSize, Panel2MinSize is set before Size), and when default size of the control is {Width=150, Height=100} setting Panel2MinSize to 500 would cause the exception. It is inconvenient, but you can set Panel2MinSize in code after InitializeComponent (in Sub New or Form Load for example). I haven't encountered this problem before nor looked it up, so there could be some clever workaround I haven't though about.
 

Latest posts

Back
Top