Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am working on some window based application(C#) its a Mobile device application.I have two forms like Form1() and Form2() and Form1() has one method

C#
public void Test()
       {
           MessageBox.Show("Hello Parent");
       }


I want to call this method from Form2() but without creating any object of Form1(). How can I do that.

Thanks in Advance.
Vivek
Posted
Updated 18-Feb-14 0:12am
v2

1 solution

You can't, not like that. That method needs a class instance. You could make it static:
C#
public static void Test()
   {
   MessageBox.Show("Hello Parent");
   }
But then you can't access any of the form fields, properties or other non-static methods from within the Test method.
 
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