471,309 Members | 1,075 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

commuicating between 2 forms

Hi,
I have 2 forms, I want to call a method from the other form, how can I do this.
TIA
Dec 21 '05 #1
4 939
To call a method you need to have a reference to the form. Once you have the
reference just call the method.

For example if form1 wants to call a method of form2, when you create the
forms create first form2 and them pass the reference when creating form1.
You can use constructor overload for example.
--

Stoitcho Goutsev (100) [C# MVP]

<Co**********@al.com> wrote in message
news:11****************@dyke.uk.clara.net...
Hi,
I have 2 forms, I want to call a method from the other form, how can I
do this.
TIA

Dec 21 '05 #2
private void MyMethod()
{
OtherForm frm = new frmOtherForm;
frm.Show();
frm.SomeMethod();
}

or better using events..

private void MyMethod()
{
OtherForm frm = new frmOtherForm;
frm.Show();

if(signalEvent != null)
signalEvent(this, EventArgs.Empty);
}
<Co**********@al.com> wrote in message
news:11****************@dyke.uk.clara.net...
Hi,
I have 2 forms, I want to call a method from the other form, how can I
do this.
TIA

Dec 21 '05 #3
Hi,

Normally you keep a reference to one of the forms in the other form.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<Co**********@al.com> wrote in message
news:11****************@dyke.uk.clara.net...
Hi,
I have 2 forms, I want to call a method from the other form, how can I
do this.
TIA

Dec 21 '05 #4
Create an instance of the other form and call a method.
Though if this method has nothing to do with UI, I would recommend putting
in a seperate class (not a form) and call from the class instance.


"Co**********@al.com" wrote:
Hi,
I have 2 forms, I want to call a method from the other form, how can I do this.
TIA

Dec 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Joshua Russell | last post: by
15 posts views Thread by Joshua Kendall | last post: by
3 posts views Thread by Lloyd Sheen | last post: by
3 posts views Thread by Geraldine Hobley | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.