2012-03-06 46 views
0

下面的測試代碼,當打開窗口時,它也會彈出hello消息框。這聽起來是在打開窗口後運行fun _ ->後的代碼。 當我調試,看不test001,似乎不是一個跑一個,像fun _ ->後無法運行該代碼:應該在繼承窗口後點擊事件添加?

let test001 = MessageBox.Show("hello") 
type Server() as this = 
    inherit windows 
     do connectionButton.Click.Add (fun _ -> test001 
              tc.Connect("localhost", 2626)) 

回答

2

由於test001是一個值,它僅被評估一次。你需要的是一個函數,它會在每次調用時彈出一個MessageBox:

let test001() = MessageBox.Show("hello") // test001 is now a function 
type Server() as this = 
    inherit windows 
     do connectionButton.Click.Add (fun _ -> test001() |> ignore 
               tc.Connect("localhost", 2626)) 
0

你需要這樣的

假設從Server繼承創建Server實例System.Windows.Form

System.Windows.Forms.Application.Run(new Server())