Interactive Session #6: Winforms SplitContainer

The SplitContainer allows to add two forms separated by a bar to another form. First we need a form again.

> open System.Windows.Forms;;
> let f = new Form();;

val f : Form = System.Windows.Forms.Form, Text: 

> f.Visible <- true;;
val it : unit = ()

Then we are adding the SplitContainer as its only control element. The left and right element of the SplitContainer are added to SplitContainer.Panel1 and .Panel2 respectively.

> let s = new SplitContainer();;

val s : SplitContainer = System.Windows.Forms.SplitContainer

> f.Controls.Add(s);;
val it : unit = ()
> s.Dock <- DockStyle.Fill;;
val it : unit = ()
> let t = new TreeView();;

val t : TreeView = System.Windows.Forms.TreeView, Nodes.Count: 0
> let t = new TreeView();;

val t : TreeView = System.Windows.Forms.TreeView, Nodes.Count: 0

> s.Panel1.Controls.Add(t);;
val it : unit = ()

> let txt = new TextBox();;

val txt : TextBox = System.Windows.Forms.TextBox, Text: 

> s.Panel2.Controls.Add(txt);;
val it : unit = ()
> let f = new Form();;        

val f : Form = System.Windows.Forms.Form, Text:

As you can see the TreeView and the TextBox is visible side by side, however they do not fill the entire space, therefore we need to set the Dock property of each element to fill the space given by the SplitContainer (which itself has to fill the complete form).

> t.Dock <- DockStyle.Fill;;                                                         
val it : unit = ()
> txt.Dock <- DockStyle.Fill;;                                                      
val it : unit = ()
> txt.Multiline <- true;;
val it : unit = ()

Further reading:

Advertisements
This entry was posted in Getting Started, GUI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s