Skip to content

Instantly share code, notes, and snippets.

@MattMS
Created July 21, 2019 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattMS/d0e4a2934c898e223acee7ab7c1ee845 to your computer and use it in GitHub Desktop.
Save MattMS/d0e4a2934c898e223acee7ab7c1ee845 to your computer and use it in GitHub Desktop.
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