What is the best approach to keep opened window form info?

G

Guest

Hello, friends,

In Windows Form applicaitons, it is often that a form window may need to
interact with other form windows. For example, clicking on a command button
in one form may bring another form to foreground and display text/image
accordingly. Do we normally keep global refrences somewhere for each opened
form windows, so that it is possible for opened windows to interact with each
other? For example:

public static formCollection
{
public static frmWindow1 frm1;
public static frmWindow2 frm2;
public static frmWindow3 frm3;
}

Or, do we want each window form only to keep references to the opened forms
it may need individually?

What is the best approach for this? Any reference papers? Thanks a lot.
 
K

Kevin Spencer

In a Windows Forms application, there is one form that is the main form of
the thread. Other forms are launched from this one. So, you need to declare
the other forms in the main form, but do NOT make them static. Then you can
reference the other forms and their data from the main form.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

Thanks, Kevin.

If that is the case, I need to declare each opened form at Main form scope,
not in its method scope, right?

I saw sample source code like the follows, and once this form is
instantiated, it can no longer be referenced:

private void mainToolStripMenuItem_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;

frmWindow1 frm1= new frmWindow1 ();

frm1.Show();

Cursor = Cursors.Default;
}

)

Do you know any links to good reference papers on this? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top