Hi VBP,
The Windows Form Designer generated code is <not>, as Armin states, a
'mustn't touch' area. It is <recommended> that you avoid doing anything in
that area. Articles on MSDN actually advise making changes there in certain
circumstances.
The reasons against are two-fold. The first is to save you losing changes.
The second is so that you don't confuse the Designer.
To explore your problem, I made a Form with a Panel and a Label, Button
and AxBrowser inside the Panel. I then changed them all to Public and rebuilt
the Solution. No problem. To test whether having an event handlers might make
a difference, I double clicked each to get create the defaults. This turned
the Public of the Panel back to Friend. The other Controls stayed Public.
That's the first reason why changes are not recommended - they <may> be
lost if you subsequently make alterations <in the Designer>. But if you never
change the Form using the Designer, it won't regenerate the code and lose your
changes.
The second reason is more important and the Designer will let you know in
no uncertain terms. There are two occasions on which InitializeComponent() is
required. On the second occasion - runtime - the compiled method is executed
like all other code in the app. On the first occasion - when the Form is
loaded at Design-time - the code is <not> executed. Rather, the Designer
<interprets> InitializeComponent(). This is easy enough - <it> created it so
it knows what to expect. Unfortunately, you can make code changes that look
like perfectly valid and compilable code but the Designer is unable to work
out how to interpret them.
Changing Friend to Public is one of the changes that the Designer <can>
recognise. Adding a call to another method in your Form is one that it can't.
Like I said, I created a simple duplication of your problem and the
Solution rebuilt perfectly. There may be another reason why you get the error.
However, I would tend to use a ReadOnly Public property which gives access
to the Label and ActiveX Controls. This will keep the code out of the
Designer area - no later developer can inadvertantly cause the Friend to
Public change to be undone; and the subtle difference in behaviour is not
hidden away in autogenerated code. The use of Properties will effectively
document the importance of access to these Controls. And lastly, although
you're a better programmer than that ;-), the other Form would not be able to
make any change to these Controls themselves - only to their properties.
Regards,
Fergus
|