p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2005 (http://p2p.wrox.com/forumdisplay.php?f=138)
-   -   Hosted Form of Component (http://p2p.wrox.com/showthread.php?t=67005)

angelboy March 30th, 2008 09:48 AM

Hosted Form of Component
 
Hi,
I created a class derived from Component Class.
i want to Add a Method that returns the Form that hosts my component.
this method called FindForm();
for example supose i add a new instance of myComponent into the Form1.
Now, i want when i write this code :

Form hostedForm =myComponent1.FindForm();

the hostedForm must be Form1.

what code i must write inside the FindForm Method?

regards

samjudson March 30th, 2008 11:11 AM

Why not just inherit from Control instead and its done for you. (Control is a sub class of Component).

/- Sam Judson : Wrox Technical Editor -/

angelboy March 30th, 2008 03:41 PM

Quote:

quote:Originally posted by samjudson
 Why not just inherit from Control instead and its done for you. (Control is a sub class of Component).

/- Sam Judson : Wrox Technical Editor -/
I want to create a none vishual component.
when your class inherit from Control Class, it create a visual component for you..

samjudson March 30th, 2008 04:03 PM

I suspect its something to do with the Container property, but I'm not 100% sure to be honest. Try checking if the Container is a Form, and if so then there is your form.

/- Sam Judson : Wrox Technical Editor -/

angelboy March 31st, 2008 01:59 AM

Quote:

quote:Originally posted by samjudson
 I suspect its something to do with the Container property, but I'm not 100% sure to be honest. Try checking if the Container is a Form, and if so then there is your form.

/- Sam Judson : Wrox Technical Editor -/
No, i use Container property too.
but this doesn't work.
when i use this property it give an exception ("object referncecs not set to an instance of an object")

samjudson March 31st, 2008 05:20 AM

OK, I've had a play around and I'm afraid I can't work this one out. An option would be to just have a control with a 0x0 user interface - or set it to hidden in the constructor.

You might want to ask on the Microsoft forums as you might get some people more knowledgeable on there who knows a way of doing this.

/- Sam Judson : Wrox Technical Editor -/

robzyc March 31st, 2008 05:44 AM

This sounds like an interesting problem although I am confused..

Where are you calling this code from? If you are in the Form, use this, if you are outside the form, then surely you have instantiated a Form which either contains the component, or instantiated a form to Add to the component (or something)?

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>

angelboy March 31st, 2008 02:36 PM

Quote:

quote:Originally posted by robzyc
 This sounds like an interesting problem although I am confused..

Where are you calling this code from? If you are in the Form, use this, if you are outside the form, then surely you have instantiated a Form which either contains the component, or instantiated a form to Add to the component (or something)?

Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>

lets me to explain this problem in another way.

many of controls has a Method called FindForm(), such as Button.
imaging there is a button on the Form1(the name of button is button1)

Now,
when you write " button1.FindForm(); ", it will be return Form1.

I Want to write a Method Like FindForm method Of the Button Class with samely action.

hope you understand


All times are GMT -4. The time now is 11:18 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.