Application startup events?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello all, I am wondering how to trap application load event on a windows
forms c# application.

My objective is to instanciate my own windows forms on the fly based on some
registry settings.

where in the visual studio project can I write this code? I need to know
where does the application starts loading...

Thanks,

David Mansilla
 
Application.Run(new Form1()); starts the message loop and the application
effectively starts.
Form.Load event is fired then

You may want to handle the Form's Load event if I understand right
place this code in the class inheriting from Form

this.Load += new EventHandler(Load); //in some initialization routine

private void Load(object sender, EventArgs e)
{
//do what you need to do before the application starts
}

VS.NET allows you to handle load event by double clicking he form in
designer
 
My objective is to instanciate my own windows forms on the fly based on some
registry settings.
where in the visual studio project can I write this code? I need to know
where does the application starts loading...

In C#, it's the Main method. If you look inside the code for your main
Windows form, you will see that the Designer has created a static
method called Main. (It's probably called something different in VB,
but there will be a corresponding method in VB. There has to be.) If
you examine the code in that method, you will see it calling
Application.Run and passing a constructed instance of the main form
that the Designer created for you when you created the Windows Forms
project.

The way I see it, you have two choices.

1. If you want your application to start up with a different main form
depending upon registry settings, then do the registry lookup in the
Main method, and change the Application.Run() call to pass in an
instance the appropriate form, based on the registry settings.

2. If you want your application to start with the main form that you
created in the designer, but then after that to bring up different
forms based on registry settings, then do the registry lookup wherever
you need to in your main form's code. I doubt this is the case, though,
based on the phrasing of your question.
 
Back
Top