The Why and How of the SplitContainer Control - Events related to the SplitContainer Control
(Page 6 of 6 )
The object browser shows two events related to the SplitContainer Control. They are SplitterMoving and SplitterMoved.
The following code snippet shows how you may visualize the two events. For those who are familiar with Visual Basic 6, the vertical and horizontal scroll bars had this feature. The SplitterMoving event captures the dynamic changes while the SplitterMoved event looks at the splitter after it has moved and come to a rest.
Double click the SplitContainer control onto a new form. Add two text boxes to the form as shown. In the code box you can use the drop-down to get the event codes as shown.

Public Class Form1
Private Sub SplitContainer1_SplitterMoved(ByVal sender As Object, _
ByVal e As System.Windows.Forms.SplitterEventArgs) Handles _
SplitContainer1.SplitterMoved
Dim strg As String = ""
strg = strg + "SplitContainer Splitterwidth is: " & _
SplitContainer1.SplitterWidth.ToString & vbCrLf
strg = strg + "SplitterContainer SplitterDistance is: " & _
SplitContainer1.SplitterDistance.ToString & vbCrLf
strg = strg + "SplitterContainer Panel1 width is: " & _
SplitContainer1.Panel1.Width & vbCrLf
strg = strg + "SplitContainer width: " & _
SplitContainer1.Width.ToString
TextBox1.Text = strg
End Sub
Private Sub SplitContainer1_SplitterMoving(ByVal sender As Object, _
ByVal e As System.Windows.Forms.SplitterCancelEventArgs) Handles _
SplitContainer1.SplitterMoving
Dim strg As String = ""
strg = strg + "SplitterContainer Panel1 width is: " & _
SplitContainer1.Panel1.Width & vbCrLf
TextBox2.Text = strg
End Sub
End Class
When you run the program you can see that data is captured while the SplitContainer is still moving. It is important that the hardware works well so that you can see the effects while moving. To grab the splitter more effectively, the splitter increment was set at 1 and the splitter width was set at 10. The picture shows the form at an intermediate dragged position.

Summary
The SplitContainer control is a very useful control to rapidly design user interfaces similar to those used in "Explorer" type programs. The VS 2005 IDE has numerous windows with this control, both simple and nested types. Many of the properties can be set in the design and most of the rest can be programmatically controlled. By combining the other ASP.NET 2.0 specific controls it is possible to deliver a rich user experience with a minimum of code.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |