|
-
Aug 29th, 2007, 09:06 AM
#1
Thread Starter
Junior Member
MDI app (keep track of opening/closing forms)
Hi all,
I'm fairly new to c# and have currently been working on a project containing mdi forms.
This is how the project is layed out.
Parent form is called Street_Index. This contains a menu strip which can open 2 different forms.
* Street_Search
* Office_Search
Within the Street_search form there is a button that i click that returns the results in another form called Search_Results.
Search Results contains a grid and on double clicking the column of the grid it returns the results of that row back to Street_Search form which displays them in textboxes, grid, combobox, etc..
Within the Office_Search form there is also a button that opens the Search_Results form and then from there you can double click on the grid within Search_Results and open up Street_Search form which will display the results as previous.
Now on to the question. What is the cleanest possible way to check to see if a childform is open or not and if it is bring it into focus/refresh it?
Thanks in advance
Take care all.
Last edited by RiverX; Aug 29th, 2007 at 09:11 AM.
-
Aug 29th, 2007, 09:39 AM
#2
Re: MDI app (keep track of opening/closing forms)
If I read it correctly, you only ever want ONE instance of Search_Results open correct?
Search for "singleton form" on the forums and you will find multiple examples of how to make this happen. Good luck.
-
Aug 29th, 2007, 09:56 AM
#3
Thread Starter
Junior Member
Re: MDI app (keep track of opening/closing forms)
I would like one instance of all of them. Say for example i click on office_search and hit search it brings up the results_form. From there i double click on a cell in the grid and it brings up the street search form. Now if i clear the street search form and decide to run a search again i get 2 results form open and if i click on a grid cell within any of the results form i get 2 search_street forms open, or if i click on the menu bar for office search again in the parent form i get 2 office_search forms open etc..
You see what im getting at lol. I think i confused myself.
-
Aug 29th, 2007, 10:12 AM
#4
Re: MDI app (keep track of opening/closing forms)
Alright. Then you can use the Singleton pattern for all of your forms. Here are a couple of posts about them but you can fine a whole lot more.
http://vbforums.com/showthread.php?t...ight=singleton
http://vbforums.com/showthread.php?t...ight=singleton
-
Aug 29th, 2007, 11:29 AM
#5
Thread Starter
Junior Member
Re: MDI app (keep track of opening/closing forms)
Hi, Thanks for the links. I got it to work for the parent form.
Heres what i did. I put the following in the child forms
Code:
1.
public partial class Form2 : Form
2.
{
3.
private static Form2 _instance;
4.
5.
public static Form2 Instance
6.
{
7.
get
8.
{
9.
if (_instance == null || _instance.IsDisposed)
10.
{
11.
_instance = new Form2();
12.
}
13.
14.
return _instance;
15.
}
16.
}
17.
18.
private Form2()
19.
{
20.
InitializeComponent();
21.
}
22.
}
And this in the parent forms on the menuitemclick event.
Code:
1.
private void ShowChildForm()
2.
{
3.
Form2.Instance.MdiParent = this;
4.
Form2.Instance.Show();
5.
Form2.Instance.Activate();
6.
}
What would i need to do to check it within the other child forms as well?
Last edited by RiverX; Aug 29th, 2007 at 11:54 AM.
-
Aug 29th, 2007, 11:56 AM
#6
Thread Starter
Junior Member
Re: MDI app (keep track of opening/closing forms)
Okay what i did was replace form frm = new form() with form frm = form.Instance and it seems to be working correctly.
Is this what i am supposed to do or is the method im using wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|