|
|
Error 1 An object reference is required for the non-static field, method, or property
|
|
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Feb 5, 2011, 2:26 PM
FroglegPosted Feb 5, 2011, 1:45 PM
namespace StaticMethod
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public static void Method1()
{
Form1 Fm1Instance = new Form1();// need instance
Fm1Instance.Method2();
}
private void Method2()
{
MessageBox.Show("Method2");
}
public static void Method3()
{
Method4();// can call static
}
public static void Method4()
{
MessageBox.Show("Method4");
}
private void bttnShowForm2_Click(object sender, EventArgs e)
{
Form2 fm2 = new Form2();
fm2.Show();
}
private void bttnmethod1_Click(object sender, EventArgs e)
{
Method1();
}
private void bttnMethod4_Click(object sender, EventArgs e)
{
Method3();
}
}
}
Form2-------------
namespace StaticMethod
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void bttnMethod1_Click(object sender, EventArgs e)
{
Form1.Method1();
}
}
}