MessageThis() is private, which means it can only be called from frmMain.
Making it public will make it callable from AnotherClass, but only if
AnotherClass has an instance of frmMain available to it, for example:
frmMain frm = new frmMain();
frm.MessageThis(text);
The above is a trivial example to get the idea across of needing an instance
variable to call the method from. I realize that you wouldn't likely
actually use it the way I illustrate.
Making MessageThis() public AND static would make it callable as
frmMain.MessageThis() (that is, will make the method available from the
class itself without requiring an instance) but I presume that MessageThis()
is supposed to receive a message on behalf of an instance of frmMain; if so,
then making the method static wouldn't work because the method wouldn't then
have access to instance data of frmMain.
If you could explain what you're actually trying to accomplish perhaps we
could find a way to your solution.
--Bob
"Typpo" <ot********@optonline.net> wrote in message
news:ut*************@TK2MSFTNGP10.phx.gbl...
Hi,
This question is somewhat basic. Is it possible to call a method in
frmMain, using another class? Here's a snippet:
partial class frmMain : Form
{
private void MessageThis(String text)
{
MessageBox.Show(text);
}
}
public class AnotherClass
{
public AnotherClass(text)
{
frmMain.MessageThis(text); //doesn't work
MessageThis(text); //doesn't work
//and so on...
}
}
I've dabbled with public and static methods, etc, but I can't seem to find
the correct way.
Thanks.