passing a form to a constructor.

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
 
A

Alberto Poblacion

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.
 
J

Jon Skeet [C# MVP]

<"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);
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top