Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ulteriori informazioni su F# all'indirizzo http://fsharp.net
- open System
- open System.Drawing
- open System.Windows.Forms
- let form =
- let temp = new Form(Text = "Ciao!", Height = 600, Width = 800)
- let pointsMasterList = ref []
- let pointsTempList = ref[]
- let mouseDown = ref false
- let pen = ref(new Pen(Color.Black))
- temp.MouseDown.Add(fun _ -> mouseDown := true)
- let leftMouse, rightMouse =
- temp.MouseDown
- |> Event.partition (fun e -> e.Button = MouseButtons.Left)
- leftMouse.Add(fun _ -> pen := new Pen(Color.Black))
- rightMouse.Add(fun _ -> pen := new Pen(Color.Red))
- let mouseUp _ =
- mouseDown := false
- if List.length !pointsTempList > 1 then
- let points = List.toArray !pointsTempList
- pointsMasterList :=
- (!pen, points) :: !pointsMasterList
- pointsTempList := []
- temp.Invalidate()
- let mouseMove (e: MouseEventArgs) =
- pointsTempList := e.Location :: !pointsTempList
- temp.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))
- temp.MouseUp |> Event.add mouseUp
- temp.MouseMove
- |> Event.filter(fun _ -> !mouseDown)
- |> Event.add mouseMove
- temp.Paint |> Event.add paint
- temp
- Application.Run(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement