Stream Layout

Generally, Windows Forms controls are positioned absolutely within their parent control. Other frameworks use explicit layout strategies, which can be very useful. For instance, the AutoVarDialog form uses automatic control layout. CLRForm defines a useful StreamLayout class, which works rather like writing to a file; each new control is placed after the last, until there's an explicit request for a 'new line'.

This example attaches a rough-and-ready toolbar to a form. A Panel control is a useful tool in composing forms; by default it does not have a border. It is easy to attach it to the top of the form with DockStyle.Top. The StreamLayout is used to put the controls in a nice row:

-- layout1.wlua
require 'CLRForm'
panel = Panel()
layout = StreamLayout(panel)
b = Button()
b.Text = "One"
b = Button()
b.Text = "Two"
t = TextBox()
form = Form()
form.Text = "Hello, World!"
panel.Dock = DockStyle.Top