Re: Making a method public

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Thu, 13 Sep 2007 16:48:10 -0500, "Tom Woods" <twoods@xxxxxxxxxxx>
wrote:

I'm new to C# and was wanting to access a method in the main form from
another form

frmMain has a method as such:
public void AddNewForm(string s, int Id)

{

}



However when I'm in a click event in another form, I cannot see AddNewForm
when addressing frmMain.AddNewForm.

Any one know what I'm I doing wrong?

Thanks,

Tom



Hi Tom,
I am assuming that you want to access an instance of frmMain that will
be running at the time and frm2 is instantiated by some action on
frmMain.
So declare a public variable of type frmMain in frm2 and assign it
when you are instantiating frm2
i.e.
in frm2
public frmMain myFrmMain;

In the appropriate point in frmMain
frm2 f = new frm2();
f.myFrmMain = this;
f.show();

hth
Bob

.



Relevant Pages

  • Re: Making a method public
    ... So declare a public variable of type frmMain in frm2 and assign it ... when you are instantiating frm2 ... public frm2(frmMain frm) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hungarian notation pros vs cons
    ... do you talk about "frmMain?" ... notation was invented as a work-around for the weakly typed Windows ... API, where the same types (int, char*, etc.) were used for multiple ...
    (microsoft.public.dotnet.languages.csharp)
  • Making a method public
    ... I'm new to C# and was wanting to access a method in the main form from ... frmMain has a method as such: ... public void AddNewForm ... when addressing frmMain.AddNewForm. ...
    (microsoft.public.dotnet.languages.csharp)
  • MAIN and EVENTS in a WINFORM
    ... you create a new instance of your main form (we call frmMain) and run that form. ... public void Main{ ... Then - in your frmMain, you can either run routines in the constructor, or capture the Load event and run you're routines there. ... Is it possible to mix both in a winform application? ...
    (microsoft.public.dotnet.framework.windowsforms)