2008年3月31日

How To Use Splitters Controls [ Splitters ]

範例1:


6. How To Use Splitters Controls [ Splitters ]
An Example:



1. Draw a panel on the form

2. Draw a textbox on the panel ( TextBox1.width is ( 1/2 Panel1.width ) )

3. Set TexBox1's Dock property to Left

4. Draw a splitter on the panel and set its Dock property to Left

5. Run Your Application

6. Now resize your TextBox1 by dragging the splitter


範例2:
An Explorer-Style Application
You are attempting to produce an interface in the format of the Windows Explorer, Outlook, and other applications. This interface will have a TreeView along one side of the form and a ListView on the other, and have the capability to move the dividing line between the two controls to resize them (see Figure 3.17).



Figure 3.17

The standard Explorer style of form layout.

This style of layout is easy to accomplish with the new features of Windows forms, but the specific order in which you add items to your form is important.

Starting with a blank form, add a TreeView control and set its Dock property to Left.
Add a Splitter control; it will automatically dock to the left and take its place along the right side of the TreeView.
Add a ListView control and set its Dock property to Fill.
That's it. The ListView will fill whatever space isn't being used by the TreeView and the Splitter will allow you to adjust the relative size of the two areas.

That is all of the sample resizing scenarios covered in this chapter, but that certainly is not the extent of layouts that can be created.