|
C# 2005 For discussion of Visual C# 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
March 30th, 2008, 09:48 AM
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
March 30th, 2008, 11:11 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Why not just inherit from Control instead and its done for you. (Control is a sub class of Component).
/- Sam Judson : Wrox Technical Editor -/
|
March 30th, 2008, 03:41 PM
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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..
|
March 30th, 2008, 04:03 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
March 31st, 2008, 01:59 AM
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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")
|
March 31st, 2008, 05:20 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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 -/
|
March 31st, 2008, 05:44 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>
|
March 31st, 2008, 02:36 PM
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
|