Created
July 21, 2019 09:28
-
-
Save MattMS/d0e4a2934c898e223acee7ab7c1ee845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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