Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:54 AM.


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