Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System.Windows.Forms
- open System.Drawing
- // Lave en display type, der arver fra Form.
- type Display() as form =
- inherit Form()
- let fwdButton = new Button ()
- let bckButton = new Button ()
- do form.init
- member this.init =
- this.Text <- "Solar System Simulator"
- this.ClientSize <- new Size(800, 600)
- bckButton.Size <- new Size (120, 30)
- bckButton.Location <- new Point (200, 550)
- bckButton.Text <- "Go back in time"
- fwdButton.Size <- new Size (120, 30)
- fwdButton.Location <- new Point (400, 550)
- fwdButton.Text <- "Progress Simulation"
- // fwdButton.Click.Add (fun x -> printfn "Yo!" |> ignore)
- this.Controls.Add fwdButton
- this.Controls.Add bckButton
- // Tag nogle funktioner og knyt dem til Mouseevents
- member this.setMouseEventFunctions(l) =
- let setEventFunction (tuple: (MouseEventArgs -> unit) * string) =
- match tuple with
- | (_,"mouseDown") -> this.MouseDown.Add (fst tuple)
- printfn "Added mouseDown"
- | (_,"mouseUp") -> this.MouseUp.Add (fst tuple)
- printfn "Added mouseUp"
- | (_,"mouseClick") -> this.MouseClick.Add (fst tuple)
- printfn "Added mouseClick"
- | _ -> printfn "Added nothing. \nFunction: %A\nString: %s"
- (fst tuple) (snd tuple)
- List.map setEventFunction l
- // Tag nogle funktioner og knyt dem til Events
- member this.setButtonEventFunctions(l) =
- let setEventFunction (tuple: (System.EventArgs -> unit) * string) =
- match tuple with
- | (_, "fwdButton") -> fwdButton.Click.Add (fst tuple)
- printfn "Added fwdButton"
- | (_, "bckButton") -> bckButton.Click.Add (fst tuple)
- printfn "Added bckButton"
- | _ -> printfn "Added nothing. \nFunction: %A\nString: %s"
- (fst tuple) (snd tuple)
- List.map setEventFunction l
- type Controller() as controller =
- let myEvent a (e:MouseEventArgs) =
- printfn "Mouse%s: %A" a e.Location
- let display = new Display()
- do controller.init
- member this.Display = display
- member this.init =
- printfn "Running init"
- display.setMouseEventFunctions([
- (myEvent("Down") , "mouseDown");
- (myEvent("Up") , "mouseUp");
- (myEvent("Click") , "mouseClick")]) |> ignore
- display.setButtonEventFunctions([
- ((fun x -> printfn "Forward!") , "fwdButton");
- ((fun x -> printfn "Back!") , "bckButton")]) |> ignore
- let c = new Controller()
- Application.Run c.Display
Add Comment
Please, Sign In to add comment