Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- open System.Drawing
- open System.Windows.Forms
- let mainForm =
- let form = new Form(Text = "Ciao!", Width = 800, Height = 600)
- let pointsMasterList = ref []
- let pointsTempList = ref[]
- let mouseDown = ref 0
- let pen = ref(new Pen(Color.Black))
- let btnClear = new Button(Text = "Clear", Size = new Size(50, 20), Location = new Point(500, 500))
- let btnClose = new Button(Text = "Close", Size = new Size(50, 20), Location = new Point(500, 530))
- btnClear.Click
- |> Event.add(fun _ -> pointsTempList := []; pointsMasterList := []; form.Invalidate())
- btnClose.Click
- |> Event.add(fun _ -> exit 0)
- let mouseUp _ =
- printfn "Mouse uppin'"
- mouseDown := !mouseDown - 1
- if List.length !pointsTempList > 1 then
- let points = List.toArray !pointsTempList
- pointsMasterList :=
- (!pen, points) :: !pointsMasterList
- pointsTempList := []
- form.Invalidate()
- let mouseMove (e: MouseEventArgs) =
- pointsTempList := e.Location :: !pointsTempList
- form.Invalidate()
- let paint (e: PaintEventArgs) =
- if List.length !pointsTempList > 1 then
- e.Graphics.DrawLines
- (!pen, List.toArray !pointsTempList)
- !pointsMasterList
- |> List.iter (fun (pen, points) -> e.Graphics.DrawLines(pen, points))
- let (leftMouse, otherMouse) =
- form.MouseDown
- |> Event.partition(fun e -> e.Button = MouseButtons.Left)
- let (rightMouse, otherMouse) =
- otherMouse
- |> Event.partition(fun e -> e.Button = MouseButtons.Right)
- leftMouse
- |> Event.filter(fun _ -> !mouseDown = 0)
- |> Event.add(fun _ -> pen := new Pen(Color.Black))
- rightMouse
- |> Event.filter(fun _ -> !mouseDown = 0)
- |> Event.add(fun _ -> pen := new Pen(Color.Red))
- form.MouseDown
- |> Event.add(fun _ -> mouseDown := !mouseDown + 1; printfn "%d" !mouseDown)
- form.MouseUp
- |> Event.add mouseUp
- form.MouseMove
- |> Event.filter(fun _ -> !mouseDown > 0)
- |> Event.add mouseMove
- form.Paint
- |> Event.add paint
- form.Controls.Add(btnClear)
- form.Controls.Add(btnClose)
- form
- [<STAThread>]
- do Application.Run(mainForm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement