Question on Component


G

Guest

Hi experts,

I created a custom Component in VS.NET 2003. From my component, I need to
catch the Load event of the parent Form. The question is how can I get the
reference to the parent instance, without passing it to the constructor of my
component (because VS.NET designer use default constructor at design-time.)

Thanks in advance.

Dotnetjunky
 
Ad

Advertisements

S

Stoitcho Goutsev \(100\) [C# MVP]

Dotnetjunky,

AFAIK you can't unless you create your own custom designer and serialize
code that sets the form reference to a property of your component. See how
MainMenu, for example, gets the reference to the form.
 
G

Guest

Hi, thanks for your answer. Here's the next question :), hope you can help
me too.

So now, I have successfullly hooked up to the parent Form's event. In the
event handler, my component would perform some checking on the machine. If
the check fails, I want to close the Form and exit the main application. If I
call Application.Exit(), nothing happens. If I call parent.Close(), the form
does close, but all the event handlers registered to the form's
Closed/Closing events get fired before that, which I don't want. Not to
mention that the Closing event handlers can stop the form from closing by
setting Cancel property of the CancelEventArgs object to 'false'. How to
workaround this issue ? What I want is close the form immediately without any
other subsequent actions performed.

Thanks in advance.


Stoitcho Goutsev (100) said:
Dotnetjunky,

AFAIK you can't unless you create your own custom designer and serialize
code that sets the form reference to a property of your component. See how
MainMenu, for example, gets the reference to the form.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Dotnetjunky said:
Hi experts,

I created a custom Component in VS.NET 2003. From my component, I need to
catch the Load event of the parent Form. The question is how can I get the
reference to the parent instance, without passing it to the constructor of
my
component (because VS.NET designer use default constructor at
design-time.)

Thanks in advance.

Dotnetjunky
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Dotnetjunky,

Do you have more code after Application.Exit? Some code after
Application.Exit might stop the the application from exiting (e.g. showing
message boxes). This has good chances to happen if you have more then one
Load event handlers. Application.Exit should be the last thing you do before
exit.
Anyways if it is not the case and you can't find out what cause this
behavior you can workaround by calling Environment.Exit instead. But bear in
mind that unlike Application.Exit which stops only the message loops in the
application domain Environment.Exit ends the process. Which in turn means
that if you run more then one application domains in the same process they
will be closed as well.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Dotnetjunky said:
Hi, thanks for your answer. Here's the next question :), hope you can
help
me too.

So now, I have successfullly hooked up to the parent Form's event. In the
event handler, my component would perform some checking on the machine. If
the check fails, I want to close the Form and exit the main application.
If I
call Application.Exit(), nothing happens. If I call parent.Close(), the
form
does close, but all the event handlers registered to the form's
Closed/Closing events get fired before that, which I don't want. Not to
mention that the Closing event handlers can stop the form from closing by
setting Cancel property of the CancelEventArgs object to 'false'. How to
workaround this issue ? What I want is close the form immediately without
any
other subsequent actions performed.

Thanks in advance.


Stoitcho Goutsev (100) said:
Dotnetjunky,

AFAIK you can't unless you create your own custom designer and serialize
code that sets the form reference to a property of your component. See
how
MainMenu, for example, gets the reference to the form.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Dotnetjunky said:
Hi experts,

I created a custom Component in VS.NET 2003. From my component, I need
to
catch the Load event of the parent Form. The question is how can I get
the
reference to the parent instance, without passing it to the constructor
of
my
component (because VS.NET designer use default constructor at
design-time.)

Thanks in advance.

Dotnetjunky
 
Ad

Advertisements

V

Vlado B.

Hello everyone,

I have the same problem. I want to reference parent form from my component.
I implemented ComponentDesigner but thats all I know and can do.
Can you give me a hint how to find reference through ComponentDesigner (or
some other designer) ???

TIA,

Vlado
 

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

Similar Threads

component 2
Remoting Component --> Com+ Component: 0
Components disappear 1
Component repository 0
BackgrounWorker component 1
Containers/Components 2
Grid components 2
WebBrowser component 2

Top