'winform'에 해당되는 글 1건

  1. 2010.07.23 F# 윈도우 애플리케이션에서 마우스 이벤트 감지하기


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)




                                  <실행하여 마우스를 몇 번 클릭한 화면>


크리에이티브 커먼즈 라이선스
Creative Commons License

 

Posted by Scripter
,