Accessing methods between forms
I have Form1 and Form2. Form1 is the main form for the application, form2 is created by form1 when you click a button.
Inside Form2 I have a method called showmessage that is public and part of the Form2 class.
In form1, I create an instance of the form2 object and then call the show method and it pops up. Then I attempt to call the form2.showmessage function that I wrote but can't get to it.
What gives?
I'm new to C# and trying to get past this learning curve. Would appreciate any help you could give me.
Thanks
glenn

Scott LysleRank #49 · 31K reputationPosted Mar 6, 2007, 8:09 PM EST
http://www.c-sharpcorner.com/UploadFile/scottlysle/LimitedDataXfer01302007012304AM/LimitedDataXfer.aspx?ArticleID=98b894ff-2a4d-42b6-8aa7-7c0b210e001f
Glenn9 reputationPosted Mar 7, 2007, 3:54 AM EST
Glenn9 reputationPosted Mar 7, 2007, 3:58 AM EST
Mike GoldRank #50 · 30.6K reputationPosted Mar 7, 2007, 1:22 PM EST
The way I talk between forms is to simply pass a pointer from form1 to form2 into the constructor and keep a reference to it.
e.g.
private Form1 _form;
Form2(Form1 form)
{
_form = form;
}
public void MyMethodToCallForm1()
{
_form.DoCalculation();
}
However looking back at your post, it might be that you forgot to make your form2 method have public access.
Scott LysleRank #49 · 31K reputationPosted Mar 7, 2007, 11:05 PM EST
It is interesting that the demo did not work for you; I just checked it, it works fine including the intellisense. As Mike Gold mentioned, the key to making this work is providing public access which is not the default condition.