Call mainForm method in other classes

A

Andy

hi, i have a problem calling a method of the mainForm inside another
class
the problem is, that i am not able to create an instance of the main
form because the other class e.g ClassB is in another *.cs file,
wihich is already included in the mainform file... (->circle inclusion
not allowed!)

when i create an object of ClassB in the mainform, i pass the parent
resp. the this pointer to the constructor of CLassB an store this
handle as a Form.
--------------------------------------------------------
in file1.cs:

namespace sample
{
public class MainForm: System.Windows.Forms.Form
{
...
ClassB myClassB = new ClassB(this, ...)
...
public void doSth(int i)
{
...
}

}
}
--------------------------------------------------------

--------------------------------------------------------
in file2.cs:

namespace sample
{
Form m_FrmParent;
public class ClassB
{
public ClassB(Form parent,...)
{
m_FrmParent= parent;
...
}

public callFromClass(int i)
{
//how to call here the "doSth(int i)"
//metod of the parent??
Control.Invoke? delegate? but how??
}
}
}
 
A

Andy

thanks for your reply, but ínt classB i can't create an instance of
MainForm, because ClassB does not know anything of Sample.MainForm...
(as i said circle inclusions are not allowed)
so the code following code won't work!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top