2012-03-06 11 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

値であり、それは一度だけ評価されます。必要なのは、呼び出されるたびに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のインスタンスを作成する必要がありますtest001のでSystem.Windows.Form

System.Windows.Forms.Application.Run(new Server()) 
関連する問題