"PawelR" wrote...
In my application I have few class, and I want call function
with "master class". This is as master form (startClass) and
option window (ClassA). My question is how call function from
startClass in classA?
There are in practice two ways of doing it. The first is to make Function1
"static", i.e. a "class-member" instead of an "instance-member"
In that case you can call it from any object with:
startClass.Function1();
However, that's not what I'd recommend, and would need Function1 to deal
with only static members itself, and my guess is that it wouldn't be
appropriate in your case.
The other way and what I'd recommend is to send a reference of the instance
of startClass to the ClassA upon instantiation.
Example:
public StartClass : System.Windows.Forms.Form
{
static void Main()
{...}
public string Function1()
{...}
private callClassA()
{
// Send a reference of this
// upon instantiation of ClassA
ClassA classA = new ClassA(this); // <--
classA.ShowDialog();
}
}
public ClassA : System.WIndows.Forms.Form
{
// We need an instance member of StartClass
// to be able to reference it
StartClass parent = null;
// We modify the constructor to receive
// a reference to the StartClass instance
public ClassA(StartClass parent) : base()
{
this.parent = parent;
}
private void Fuction11()
{
// And then we can call it...
parent.Function1(); // <--
}
}
----------
Notice that I also capitalized the name of startClass to StartClass, as
that's the common practice of naming classes.
// Bjorn A