Hi Jan,
Sorry!! My apologies - I'm the stupid one. :-((
I've been playing with UserControls and working with DesignMode and it's
different with plain old Forms. And now I've found out why
When you open a Form up in Design Mode, VS doesn't call New, as I had
thought. What it does is go through ComponentInitialize, line by line, and
execute it as if it were actually being run. But it doesn't do anything that
it doesn't understand (which is why we're not supposed to make changes in that
routine). If it encounters anything there that it doesn't like it will
complain loudly.
So, my suggestion of putting DoSomethingToAllControls in New is a total
non-starter.
But !!
I also learned that if a designable class (Form, UC, etc) inherits from
another, then the constructor of <that> class <will> be called.
With
Public Class SomeForm
Inherits System.Windows.Forms.Form
the constructor of System.Windows.Forms.Form (SWFF) is called to do its
thing.
Now, consider
Public Class SomeForm_BASE
Inherits System.Windows.Forms.Form
and
Public Class SomeForm_ACTUAL
Inherits SomeForm_BASE
(where each is in a .vb file of its own)
When you show SomeForm_BASE in the Designer, you just get that Form and
the SWFF contructor. When you show SomeForm_ACTUAL, the constructor of
SomeForm_BASE is called and this can do what it likes. [As an aside, there
seems to be no way for the Base to know that it's being called on behalf of
Actual, but that may not be a problem.]
So how would this apply to your situation? Wekk, it may be more trouble
than it's worth but...
If you design your form in the usual way, SWFF constructor will be called.
Put anything in New and it won't run.
Public Class AUsefulFormWithControlsAndCodeAndEverything
Inherits System.Windows.Forms.Form
Public Sub New
MyBase.New()
InitializeComponent()
DoStuffToTheControlsOf (Me)
End Sub
: : :
: : :
End Class
VS ignores Public Sub New
It definitely calls MyBase.New but that's because of the Inherits.
It simulates a call to InitializeComponent().
There's no call to DoStuffToTheControlsOf.
But derive a new 'viewer' Form inheriting from the useful one, ie
Public Class SeeHowMyBaseLooksWhenItRuns
Inherits AUsefulFormWithControlsAndCodeAndEverything
'And no contents at all.
End Class
and DoStuffToTheControlsOf will be run. And not only New, it would seem,
but Load gets called as well - so be careful. DesignMode isn't applicable
inside the Constructor but it is within Load.
Once again, apologies for leading you astray (so confidently too, lol). If
this is of no direct use then I hope, at least, that it makes interesting
background information.
As always, any questions, give a shout. ;-)
Regards,
Fergus