Section 3.5. Create Split Windows


3.5. Create Split Windows

The new SplitContainer control makes creating split windows in Windows Forms a snap. The two panels can be side by side or one on top of the other, and you can nest splitters one within another to further divide the form.

3.5.1. How do I do that?

Create a new Windows application, name it SplitWindows, and drag a SplitContainer control onto the form. Notice that its default orientation is to split vertically. Click the smart tag, and choose Horizontal Splitter Orientation.

Now you have two panels, top and bottom. Drag a second SplitContainer control into the bottom panel. Click in the bottom-left panel and set the background color to blue. Click in the bottom-right panel and set the background color to red. Then set the upper panel to green.

Run the application. The three panels are clearly visible, and when you pass your cursor over the divisions, the cursor changes to the splitter cursor, as shown in Figure 3-19. (I've surrounded the cursor with a white box to make it easy to find.)

Figure 3-19. The splitter windows


When you create a SplitContainer control, its Dock property is automatically set to DockStyle.Fill. You can undo this to specify how much space you want your splitter to take up or you can prefill a portion of the form with a panel, and the splitter will take the remaining room.

If you undock the splitter, you can move it about within the form using the grab handles, as shown in Figure 3-20.

Figure 3-20. Moving the splitter


3.5.2. What about...

...restricting the size of the SplitContainer control?

You can set the Panel1MinSize or Panel2MinSize properties to set the minimum size of each panel. You can even stop resizing altogether by setting the IsSplitterFixed property to TRue.

Normally, when you resize the window each panel is resized proportionally. You can override that behavior, however, by setting the FixedPanel property of one of the panels to true. In that case, that panel will hold its size when the form is resized, and the other panels will adjust accordingly.

3.5.3. Where can I learn more?

For more information, see the MSDN article titled "Split Containers."



Visual C# 2005(c) A Developer's Notebook
Visual C# 2005: A Developers Notebook
ISBN: 059600799X
EAN: 2147483647
Year: 2006
Pages: 95
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net