Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

passing a form to a constructor.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Just Me - 26 Dec 2007 14:30 GMT
I want to be able to access the control members of a form from within a
class. So i designed my constructor something like this

Form1 parentForm;

ClassName ( Form1 frm )
{

   parentForm = frm;

}

But when I try and pass the form to the class it errors.

ClassName myClass( this );

What am I doing wrong ???

Cheers
Alberto Poblacion - 26 Dec 2007 14:59 GMT
>I want to be able to access the control members of a form from within a
>class. So i designed my constructor something like this
[quoted text clipped - 11 lines]
>
> What am I doing wrong ???

  I think that what you want to do is this:

     ClassName myClass = new ClassName(this);

  It will only work if it is done inside Form1, since otherwise "this"
would not be of the adequate type to pass to the constructor that you
defined.
Jon Skeet [C# MVP] - 26 Dec 2007 15:12 GMT
<snip>

> But when I try and pass the form to the class it errors.
>
> ClassName myClass( this );
>
> What am I doing wrong ???

Well, that's not the syntax used for a constructor call. You need:

ClassName myClass = new ClassName(this);

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ignacio Machin ( .NET/ C# MVP ) - 26 Dec 2007 16:42 GMT
Hi,

You need to get a book of C# , some basic stuff like syntax, etc.

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

>I want to be able to access the control members of a form from within a
>class. So i designed my constructor something like this
[quoted text clipped - 15 lines]
>
> Cheers

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.