Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old March 30th, 2008, 09:48 AM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old March 30th, 2008, 11:11 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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

/- Sam Judson : Wrox Technical Editor -/
  #3 (permalink)  
Old March 30th, 2008, 03:41 PM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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..
  #4 (permalink)  
Old March 30th, 2008, 04:03 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
  #5 (permalink)  
Old March 31st, 2008, 01:59 AM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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")
  #6 (permalink)  
Old March 31st, 2008, 05:20 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
  #7 (permalink)  
Old March 31st, 2008, 05:44 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>
  #8 (permalink)  
Old March 31st, 2008, 02:36 PM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hosted BeerHouse and sub directory gb012993 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 16th, 2008 01:48 AM
Events with IIS hosted remoting koraykazgan C# 1 May 1st, 2007 03:49 PM
Moving App to Hosted site dthoma128 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 13 December 19th, 2006 03:59 PM
Access hosted on windows server 2003? hapsmack Access 1 July 11th, 2006 12:16 AM
puzzle: about caspol and windows form component progoney Forum and Wrox.com Feedback 1 June 3rd, 2004 08:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.