modify designer generated c'tor that calls InitializeComponent?

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

When you create a Windows app, you get a two files pre-made each with
a partial class of the same class, and you also get a c'tor of your
class which calls InitializeComponent(). I guess this is cool, since
VB hides this, I believe.

I am sure it is ok for me to populate the c'tor with more of my own
stuff, as long as I don't remove the InitializeComponent call, right?
I am always a bit uneasy messing with desginer generated code, but I
think I just convinced myself it is perfectly ok to have MY c'tor do
as I please.

Zytan
 
Sure. That's why it's visible. And it's also useful place for a few things.
But there are things you should not do there. For example you should not
touch controls, wire events and things like this.
The class is still being created so be careful.
And try to put your code after the InitializeComponent() call. It's safer.
The *core* of the designer code is in the .designer.cs file that is not to
be touched, usually.
 
Sure. That's why it's visible. And it's also useful place for a few things.
But there are things you should not do there. For example you should not
touch controls, wire events and things like this.
The class is still being created so be careful.

Yes, good point. I am just going to put the initialization of my
logfile in there, since this should be the first code that is run in
the program (that is, of any code that I write).
And try to put your code after the InitializeComponent() call. It's safer.
The *core* of the designer code is in the .designer.cs file that is not to
be touched, usually.

Yes.

Thanks,
Zytan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top