Form.Load事件不会触发

时间:2014-04-07 13:25:02

标签: winforms events f#

已创建表单。可以看出,但“加载”事件不会触发。这是最简单的情况:

type Program() as this =
   let form_ = new Form(Visible=true, Text="Some Caption", Width=1024, Height=768)

   do
      form_.Load.Add(this.OnFormLoad)     
      form_.Show()

   member x.OnFormLoad(e) = 
      Trace.WriteLine("OnFormLoad() entering...")

   member x.form = form_

#if COMPILED
[<STAThread()>]
let program = new Program()
Application.Run(program.form)
#endif 

这段代码我哪里错了?

1 个答案:

答案 0 :(得分:4)

尝试从构造表单的调用中删除Visible=true

我认为当您将Visible设置为true时,会立即创建并加载表单,因此在表单构造期间(在您设置处理程序之前)会触发Load事件。我也会删除通话form_.Show()。我认为表单将由Application.Run打开。