Oleg Leonov
Oleg Leonov

Reputation: 345

Form.Load event doesn't fire

A form has been created. It can be seen, but 'Load' event doesn't fire. This is the simplest case:

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 

Where am I wrong in this code?

Upvotes: 1

Views: 264

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243041

Try removing Visible=true from the call that constructs the form.

I think that when you set Visible to true, the form gets immediately created and loaded, so the Load event is triggered during the form construction (before you setup the handler). I would also remove the call form_.Show(). I think the form will be opened by Application.Run.

Upvotes: 4

Related Questions