passing a form to a constructor.

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

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
 
Just Me said:
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 ???

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.
 
<"Just Me" <news.microsoft.com>> wrote:

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);
 
Hi,


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