Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass this object as a parameter..

current status.
ex:- acb(first parameter,second parameter,this)
this is use for the current form....
but in my project there is multipule forms.
so how can pass the multipul form's in plase of "this".

purpos.
i want to use the controls of the form.
Posted
Comments
VJ Reddy 15-May-12 5:59am    
Thank you for accepting the solution.

The last parameter in the method acb shown in the question can be defined as type System.Windows.Forms.Form, so that the current form given by this keyword and any other existing form can be passed to this method as an argument against this parameter.
 
Share this answer
 
Comments
Mohamed Mitwalli 30-Apr-12 3:46am    
5+
VJ Reddy 30-Apr-12 3:50am    
Thank you, Mohamed.
I think the vote is not updated.
Mohamed Mitwalli 30-Apr-12 13:18pm    
did it again :)
When you use this you are always talking about the current instance of whatever class you are in - in your case a form. So when you call a method using this as a parameter, you pass whichever instance if currently in use.

C#
public class MyForm : Form
   {
   ...
   public void DoSomething()
      {
      MyStaticClass.MyMethod(this);
      }
   ...
   }

MyForm mf1 = new MyForm();
MyForm mf2 = new MyForm();
mf1.DoSomething();
mf2.DoSomething();
Would pass two different instances of MyForm to the static MyMethod method.

So you already do pass multiple forms!
 
Share this answer
 
Comments
VJ Reddy 30-Apr-12 3:41am    
Nice answer. 5!
If you have to create the forms and then pass its object to the function then perhaps you can do this

lets say forms: FormA, FormB

Modify the function like:

acb(first, second, FormA frmA, FormB frmB)

then pass the form objects as:

C#
FormA fa = new FormA();
FormB fb = new FormB();

acb(first, second, fa,fb);


Please provide more details so that I can suggest better ways of doing this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900