Possible Duplicate:
How should the Form.Load event be used compared to its constructor method?
Hello,
My question is regarding good programming practices in C#. If I’m creating a application with various forms I would initialize the connection to DB inside the Load method, or it should be inside the basic Constructor of the form? As well the other code to fill the forms basic textboxes and comboboxes can be inside the Load method or it is always better to use the constructor for that purpose?
Thanks in advance,
Kornel
Whenever you want to change the state of a control that belongs to a Form, I suggest you doing this in the Form Load event.
Doing that in the constructor of the form is error prone. Have you thought about what would happen if you try to do it in the constructor, but before the
InitializeComponents()method call?About the ConnectionString, you could do that in both, because that isn’t really directly related with the Form.
You could also take a look at some open-source projects codes, to see how they do that about the
ConnectionStringor some other stuff not related with the Form:)