frmproperty is a method, and it's public - so all you need is the form instance in order to call it. And there's the rub - how do you get the form instance? should you get the form instance? Difficult to tell, without knowing more about how your forms are related.
There are three different scenarios:
1) Form1 creates and opens the Form2 instance (Form1 is the "parent", Form2 is the "child")
2) Form2 creates and opens the Form1 instance (Form2 is the "parent", Form1 is the "child")
3) Form3 creates and opens both Form1 and Form2. (Form3 is the "parent", Form1 and Form2 are the "children")
How this should be handles depends on which scenario your software is using, because "children" should not know that "parents" even exist, let alone what class they are and thus what properties and methods they contain.
See one of these:
Transferring information between two forms, Part 1: Parent to Child[
^]
Transferring information between two forms, Part 2: Child to Parent[
^]
Transferring information between two forms, Part 3: Child to Child[
^]
They mostly deal with properties, but it's exactly the same for methods.
Quote:
so this means my idea is impossible to work?
Basically, yes - in the form you are trying to do it, anyway.
You're trying to do something that isn't right. There are ways to do what you want:
1) Create a static method (or an extension method) for the Form class and pass it the Form instance you want to "adjust" - this will only work if the method sticks to standard Form properties and methods, it can't do anything specific to a derived class.
public static class GeneralMethods
{
public static void Adjust(Form f)
{
f.CenterToScreen();
f.Text = "frmlogin";
f.MaximizeBox = false;
f.MinimizeBox = false;
}
}
...
GeneralMethods.Adjust(this);
2) Create a base class for all your forms that contains the method, and derive your forms from that. The base method is available directly in all derived forms without any reference to the base class.
public class MyForm : From
{
public void Adjust()
{
CenterToScreen();
Text = "frmlogin";
MaximizeBox = false;
MinimizeBox = false;
}
}
...
public class Form1 : MyForm
{
...
Adjust();
...
}
public class Form2 : MyForm
{
...
Adjust();
...
}
In reality, MyForm would be an
abstract
form, but that gives problems with the Visual studio designer, so for the moment, just leave it at that!