F# 프로그램으로 마우스 이벤트를 감지하는 간단한 윈도우폼 애플리케이션을 작성해 보았다.
실행시키고 라벨이 았는 곳을 클릭하면 클릭 횟수가 하나씩 증가한다.
* Filename: TestMouseDownEvent.fs
*
* Compile: fsc TestMouseDownEvent.fs
* Execute: TestMouseDownEvent
*
* Date: 2010/07/23
* Author: phkim pkim __AT__ scripts.pe.kr
*)
open System
open System.Drawing
open System.Windows
open System.Windows.Forms
// Creates the user interface
let frm, lbl = new Form (), new Label()
frm.Width <- 300
frm.Height <- 300
frm.FormBorderStyle <- FormBorderStyle.Fixed3D
frm.Text <- "Test of MouseDown Event"
lbl.Size <- new System.Drawing.Size(200,30)
lbl.TextAlign <- ContentAlignment.MiddleLeft
lbl.Location <- new System.Drawing.Point(20,40)
lbl.Text <- "Click here"
lbl.ForeColor <- Color.DarkGreen
// lbl.Font <- new Font("verdana", 12.0f, FontStyle.Bold)
lbl.Font <- new Font("Lucida Console",10.0f,FontStyle.Bold)
lbl.BackColor <- Color.AliceBlue
frm.Controls.Add(lbl)
let rec loop(count) = async {
let! args = Async.AwaitEvent(lbl.MouseDown) // Wait for mouse down
lbl.Text <- sprintf "Clicks: %d" count
return! loop(count + 1) }
do
Async.Start(loop(1))
Application.Run(frm)
'프로그래밍 > F#' 카테고리의 다른 글
F# 용 GUI Hello 예제 (0) | 2011.08.14 |
---|---|
F# 윈도우 애플리케이션에서 마우스 이벤트 감지하기 2 (0) | 2010.08.11 |
30000! 빨리 계산하기 with F# (0) | 2010.07.20 |
int 타입과 bigint 타입 간 상호 변환 with F# (0) | 2010.07.18 |
Pollard's rho method 소개: 정수의 인수분해(factorizing integers) with F# (0) | 2010.07.17 |