Sir, I have two window forms, each form has some controls. I want to access control of one form from another form. I have tried two ways- 1- Make controls public and access them
You can do this in many ways...
You can declare some static getter/setter to manage a static instance of the compononent:
private static Type _myObject;
public static Type MyObject
{
get
{
return _myObject;
}
}
In this case you can access it from evrywere if you only need a specific shared object
MyClass.MyObject.Function();
Or you can define a getter for the whole class:
public class MyClass
{
static MyClass _myClass;
public static MyClass Instance { get { return _myClass; } }
public MyClass()
{
_myClass = this;
...
}
public void Hello()
{
Console.WriteLine("CIAO!")
}
}
And getting all the methods and properties of the class:
MyClass.Instance.Hello();
You can pass also the class in a constructor, property or function, but i dislike this way...