Mouse Move Event In F# windows Form Application

Here You can see that how we can Implement Mouse Move Event in F#. As you Move the Mouse it will show its position on the Form.

Example

#light
open
System
open System.Drawing
open System.Windows.Forms
 
// Create the main form
let form = new Form(ClientSize=Size(450,400))
 
// React to Mouse Move events on the form
let evtMessages =
    form.MouseMove     
     |> Event.map (fun mi ->                               
        mi.Location.ToString())    
     |> Event.map (sprintf "The position of the Mouse is %s")
     |> Event.add(fun(a) -> form.Text <- a)
 
// Show the form
form.Show()
 
// Program eventloop
while form.Created do
    Application.DoEvents()

Output

Mouse-Event-Output-1

Mouse-event-Output2.gif

Ebook Download
View all
Learn
View all