Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
open System
open System.Drawing
open System.Windows.Forms
let addClickHandler click (button: Button) =
button.Click.AddHandler (new EventHandler (click))
button
let addControl (child: Control) (parent: Control) =
parent.Controls.Add child
parent
let setFlowDirection flowDirection (panel: FlowLayoutPanel) =
panel.FlowDirection <- flowDirection
panel
let setSize w h (control: Control) =
control.Size <- Size (w, h)
control
let setTabIndex tabIndex (control: Control) =
control.TabIndex <- tabIndex
control
let setText text (control: Control) =
control.Text <- text
control
let setWrapContents wrapContents (panel: FlowLayoutPanel) =
panel.WrapContents <- wrapContents
panel
// Components
let makeButton label click =
new Button () |> addClickHandler click |> setText label
// BottomUp/TopDown, LeftToRight/RightToLeft
let makeFlowLayoutPanel direction =
new FlowLayoutPanel () |> setFlowDirection direction
// Application event handlers
let helloClick o e =
MessageBox.Show "Hiya" |> ignore
// Application
type MyForm() as form =
inherit Form ()
let panel =
makeFlowLayoutPanel FlowDirection.LeftToRight
|> addControl (makeButton "Hello there" helloClick)
|> addControl (makeButton "Hello again" helloClick)
do
form
|> setSize 640 480
|> addControl panel
|> setText "Example form"
|> ignore
[<STAThread>]
do
Application.EnableVisualStyles()
Application.Run (new MyForm ())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.