Windows Develop Bookmark and Share   
 index > Windows Forms General > Passing Form object as paramter to a function in a class
 

Passing Form object as paramter to a function in a class

Hi,

Does anyone know how to pass a form as a parameter objectto a function call in a new instantiated class,called from that same form?

For example:

I'm in a form, it has a menu, I click on it, it instantiates a class

e.g. (clsFormLauncher cFL = new clsFormLauncher();)

thenI, say,call the class' function with a parameter of the form

e.g. cFL.Constituent_Card_Open(this);

The reason for this is I want to be able to reference the form in the function,to be able to use it as the MdiParent reference when I open another form from within the class object.

I don't know how to create a function with a parameter that takes a form object:

public void Constituent_Card_Open(System.Windows.Forms fForm)

{

fConstituent fC = new fConstituent();

fC.MdiParent = fForm;

fC.Show();

}

Any ideas?

Many thanks,

Tim

Tim Grant  Tuesday, August 07, 2007 3:23 PM

Thanks,

I've got it now, the problem was for the format of the parameter in the class object, I needed:

using System.Windows.Forms;

and

cFL.Constituent_Card_Open(this);

and

public void Constituent_Card_Open(Form fForm)

for it to format correctly as a form object parameter within the function

Thanks again, helps when you 'think out loud' sometimes.

Tim

Tim Grant  Tuesday, August 07, 2007 3:42 PM
I'm having
Code Snippet

a hard time understanding whatyou want...

Pass a form as a parameter to a function call in a new instantiated class...

Code Snippet

Foo foo = new Foo();
foo.DoSomething( formInstance );



In case we initialize Foo in an instance of a Form, and we want to pass 'ourselves' (the form):

Foo foo = new Foo();
foo.DoSomething( this );

timvw  Tuesday, August 07, 2007 3:30 PM

Thanks,

I've got it now, the problem was for the format of the parameter in the class object, I needed:

using System.Windows.Forms;

and

cFL.Constituent_Card_Open(this);

and

public void Constituent_Card_Open(Form fForm)

for it to format correctly as a form object parameter within the function

Thanks again, helps when you 'think out loud' sometimes.

Tim

Tim Grant  Tuesday, August 07, 2007 3:42 PM

You can use google to search for other answers

Custom Search

More Threads

• how to know the windows logged-in user...
• helb including a static library in a windows form app
• My Windows Application Hangs if I Lock the PC and unlocks my PC
• Disposing NotifyIcon
• Get Server time in VB6
• Rollback Setup of Windows Application Developed in .NET if any Error Occurs
• form backgroundImage with transparent controls!!!!
• Anyone can help with axMediaPlayer ???
• Timer and play images at the same time
• PropertyGrid Control Cell Value???