The Splitter control The Dock Property

209 The text boxes in Figur e 5 - 13 are in ascending z-order textBox1 is lowest; textBox6 is highest. The Dock properties of the controls are set like this: textBox1.Dock = DockStyle.Left textBox2.Dock = DockStyle.Top textBox3.Dock = DockStyle.Right textBox4.Dock = DockStyle.Bottom textBox5.Dock = DockStyle.Left textBox6.Dock = DockStyle.Fill

5.3.2.2 The Splitter control

By default, the internal edges of docked controls arent draggable. To make the edge of a given docked control draggable, add a Splitter control to the form. The Splitter control must appear in the dock order immediately after the control whose edge is to be draggable, so the Splitter controls z- order must be just above that controls z-order. Further, the Splitter control must be docked to the same edge of the form as the control whose edge is to be draggable. The Splitter control provides a vertical splitter if docked left or right and a horizontal splitter if docked top or bottom. Consider again Figur e 5- 9 . To make the edge between the two text-box controls draggable, a Splitter control must be added to the form call it splitter1, and the z-order must be textBox2 highest, then splitter1, and then textBox1 lowest. This can be accomplished in the Visual Studio .NET Windows Forms Designer by adding the controls to the form in dock order textBox1, splitter1, textBox2. As previously mentioned, if the controls have already been added to the form, their z-order can be rearranged by right-clicking the controls one-by-one in dock order and choosing Bring To Front. The z-order can also be controlled in code, as previously discussed. It is possible to automate the task of Splitter creation. The subroutine in Ex am ple 5- 1 takes as a parameter a reference to a docked control and instantiates a Splitter control that makes the given controls inside edge draggable. Example 5-1. Dynamically creating a Splitter control Shared Sub AddSplitterByVal ctl As Control Create a Splitter control. Dim split As New Splitter Get the Controls collection of the given controls container. Dim controls As System.Windows.Forms.Control.ControlCollection _ = ctl.Parent.Controls Add the Splitter to the same container as the given control. controls.Addsplit 210 Move the Splitter control to be immediately prior to the given control in the Controls collection. This causes the Splitter controls z-order to be just above the given controls z-order, which in turn means that the Splitter control will be docked immediately following the given control. controls.SetChildIndexsplit, controls.GetChildIndexctl Dock the Splitter control to the same edge as the given control. split.Dock = ctl.Dock End Sub

5.4 Common Dialog Boxes