Really weird issue with VS.NET 2003

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

Guest

Hi there,

Ok, this is weird. For some reason, when I open up a windows form to edit,
there is a piece of my code being run. Here's the story:

I have a base main form that contains code that opens the COM port (as well
as doing other things). I derive my "real" main form from the base as there
will be multiple versions of my app. The problem I am running into is, if I
open the main form for editing (design view and not code view), I get a
message box pop up indicating that access is denied to the COM port. This
message box is the one contained in the base form that gets displayed during
run time if there is a problem opening the COM port.

As far as I know, nothing is being run. To be sure that was the code being
executed, I changed the text of the messagebox, saved the files, closed the
files and opened the main form again. Sure enough, up pops the newly modified
message box. I didn't compile or anything. One thing that sets off a little
red flag in the back of my mind is that there is a 3rd party control on the
derived main form that pops up a message concerning a demo license. I don't
know if that has anything to do with it.

Can anyone shed light on this? It has me stumped.

Thank you,

Carlo.
 
Hello,

the form in the designer is instantiated and its constructor called whne you
load it in the designer. so for example if you create a label and add a
messagebox in its constructor, you will see the messagebox when dropping
that label onto the form in design time as the constructor will be called
when the label created..


Cris
 
Hi,
Actually, object of the base class of the designed form has been
instantiated. That's the reason there can't be abstract form class. But,
yes, code runs when the form gets open in the designer.
 
That seems kind of odd. If the form, as in my case, is the main form and its
constructor kicks off a whole mess of operations, couldn't that cause all
kinds of problems? Is there a way of stopping this?

I've only begun seeing this problem since I converted from having just one
main form to having a base main and a derived main. Now, when I open the base
main form, everything is fine with the COM port. If I open the derived main
form, it apparently opens the COM port and nothing else can access the COM
port until I shut down Visual Studio. What is it about the derived form that
causes this problem. If I don't open the derived main form in design mode, I
can work without any problems but as soon as I open the derived form, I will
be forced to shut down Visual Studio before I can access the COM port again.

Thanks,

Carlo.
 
As I told you, the designer instantiates object of the base class of the
designed form. When you design the base form System.Windows.Forms.Form.
type is instantiated and your base constructor never gets called.
If you desingn the derived form, on the other hand, your base form gets
instatiated and the base form's constructor kicks off.

In fact, I believe, that puting such a code in the constructor is not a good
idea. I'd suggest to move that code either in dedicated Init method or in
the form's OnLoad.
All components (and the form in particualr) have property DesignMode,which
you can check and skip some code if the form is in design mode. It is
obviously, though, that in the form's constructor this property is not set.
So there is no much you can do in the construcor to prevent this from
happening.
 
Thank you very much for your help.

Carlo.

Stoitcho Goutsev (100) said:
As I told you, the designer instantiates object of the base class of the
designed form. When you design the base form System.Windows.Forms.Form.
type is instantiated and your base constructor never gets called.
If you desingn the derived form, on the other hand, your base form gets
instatiated and the base form's constructor kicks off.

In fact, I believe, that puting such a code in the constructor is not a good
idea. I'd suggest to move that code either in dedicated Init method or in
the form's OnLoad.
All components (and the form in particualr) have property DesignMode,which
you can check and skip some code if the form is in design mode. It is
obviously, though, that in the form's constructor this property is not set.
So there is no much you can do in the construcor to prevent this from
happening.
--
HTH
Stoitcho Goutsev (100) [C# MVP]


carlor said:
That seems kind of odd. If the form, as in my case, is the main form and
its
constructor kicks off a whole mess of operations, couldn't that cause all
kinds of problems? Is there a way of stopping this?

I've only begun seeing this problem since I converted from having just one
main form to having a base main and a derived main. Now, when I open the
base
main form, everything is fine with the COM port. If I open the derived
main
form, it apparently opens the COM port and nothing else can access the COM
port until I shut down Visual Studio. What is it about the derived form
that
causes this problem. If I don't open the derived main form in design mode,
I
can work without any problems but as soon as I open the derived form, I
will
be forced to shut down Visual Studio before I can access the COM port
again.

Thanks,

Carlo.
 
Back
Top