473,837 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open a Form Only Once in MDI application

Can someone help me figure out a way to open a form only once in an MDI app.

I have an MDI app that contains several forms. I use each form depending on
the type of document that the user needs to see, i.e. for documents of type
A, I use form A, for type B, form B, etc. Each document has a unique number.

I need the app to only show one document at a time, i.e. ifthe user tries to
open doc. 1 of type A, then open form A and load doc 1. If then the user
tries to open the same doc, just focus on the open form, rather than creating
a new form of type A.

I tried implementing a singleton design pattern, and it worked fine, but of
course now I can only open one form of type A, B, C etc.

Thank you for your help.
Nov 22 '05 #1
2 2952
Konstantin,

I have an app that does something like that. Here's how I do it:

In MDI Parent class, a member variable for each type of form:
private MyPictureForm m_PictureForm = null;
private MyTextEditor m_TextEditor = null;
private MySpreadsheet m_Spreadsheet = null;

and a protected property for each type of form (I fully show just the
first here):
protected MyPictureForm PictureForm
{
get { if (m_PictureForm == null)
m_PictureForm = new MyPictureForm() ;
return (m_PictureForm) ;
}
protected MyTextEditor TextEditor...
protected MySpreadsheet Spreadsheet...

The File Open handler in the main window looks like

private void onFileOpen (...)
{
if (dlgFileOpen.Sh owDialog() != DialogResult.OK )
return;

string ext = Path.GetExtensi on(dlgFileOpen. FileName);
if (ext.ToUpper(). CompareTo(".JPG ") == 0)
{
PictureForm.Loa d(dlgFileOpen.F ileName);
PictureForm.Sho w();
}
else if (ext.ToUpper(). CompareTo(".TXT ") == 0)
{
TextEditor.Load (dlgFileOpen.Fi leName);
TextEditor.Show ();
}
else if ... (other extensions)
}

Finally, in each form class, implement Load to check if the data
specified to load is already loaded. If it is appropriate to derive all your
form classes from a single base form class, you can do this in base.Load(),
instead of each seperate form class:

public void Load (string aFilename)
{
if (aFileName.Comp areTo(m_FileNam e) == 0)
return; // or throw exception, log message, whatever

m_FileName = aFileName; // next time, we'll know this file is loaded

// load the data
}

This way of implementing it doesn't take advantage of a singleton pattern.
That is, the MDI parent creates only one of each form, whether that form
class enforces singleton semantics or not. That was an appropriate choice
for my app, since most of my MDI children are like yours, i.e., one of a
kind, but I have one form class that can be instantiated multiple times.

In your MDI parent form class, always use the protected property to get
the instance of the child window class; don't refer to the member variable
(except in the property itself). That way, you're guaranteed to have it be a
non-null instance.

Good luck,

PC

"Konstantin " wrote:
Can someone help me figure out a way to open a form only once in an MDI app.

I have an MDI app that contains several forms. I use each form depending on
the type of document that the user needs to see, i.e. for documents of type
A, I use form A, for type B, form B, etc. Each document has a unique number.

I need the app to only show one document at a time, i.e. ifthe user tries to
open doc. 1 of type A, then open form A and load doc 1. If then the user
tries to open the same doc, just focus on the open form, rather than creating
a new form of type A.

I tried implementing a singleton design pattern, and it worked fine, but of
course now I can only open one form of type A, B, C etc.

Thank you for your help.

Nov 22 '05 #2
This was the default action in VB6. The best way I've found to do it in
VB.NET is to write a very small VB6 program, convert it to VB.NET and then
examine the resulting code.

"Konstantin " wrote:
Can someone help me figure out a way to open a form only once in an MDI app.

I have an MDI app that contains several forms. I use each form depending on
the type of document that the user needs to see, i.e. for documents of type
A, I use form A, for type B, form B, etc. Each document has a unique number.

I need the app to only show one document at a time, i.e. ifthe user tries to
open doc. 1 of type A, then open form A and load doc 1. If then the user
tries to open the same doc, just focus on the open form, rather than creating
a new form of type A.

I tried implementing a singleton design pattern, and it worked fine, but of
course now I can only open one form of type A, B, C etc.

Thank you for your help.

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
462
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs to see, i.e. for documents of type A, I use form A, for type B, form B, etc. Each document has a unique number. I need the app to only show one document at a time, i.e. ifthe user tries to open doc. 1 of type A, then open form A and load doc 1....
55
4688
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's not obvious how the code works if you don't know the intricacies of the Property Let/Get syntax. Likewise, I dislike (and code to minimize the use of) the VB/VBA syntax of returning a value by referring to the function name as if it were a...
1
4939
by: celtic_kiwi | last post by:
I have an Access 97 database, quite large, and have started getting the error, Error 3048: Can't Open any more databases. -The data is split from the application (front end and back end). -The application has a fair bit of VBA -The Data database resides on a network server -Generally there are 3-4 front-ends attached at any one time The application has run happily in its current state, aside from incremental changes, for over 5 years. I...
2
5628
by: celtic_kiwi | last post by:
I have an Access 97 database, quite large, and have started getting the error, Error 3048: Can't Open any more databases. -The data is split from the application (front end and back end). -The application has a fair bit of VBA -The Data database resides on a network server -Generally there are 3-4 front-ends attached at any one time The application has run happily in its current state, aside from incremental changes, for over 5 years. I...
6
25716
by: lauren quantrell | last post by:
I have a command button on a continuous subform and I want the user to click it to open a small popup form that opens in the position of the mouse (which is the same as the position of the command button on each record of the continuous subform.) I'm hoping someone can tell me how to do this. Thanks, lq
3
3790
by: stumorgan | last post by:
There is probably an extremely simple answer to this question and I'm just being foolish. I have a main form (let's say FormMain) which opens other forms (let's say Form1, Form2). How do I keep those created forms, Form1 and Form2, from closing when I close FormMain? Right now what I'm doing is threading them by wrapping the Show method and in that threaded wrapper I have a while loop that just does Application.DoEvents() as long as...
7
3711
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again. The app I've written has three ASPX pages. One is a combined page which writes a little text...
0
3234
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want to register new customer or companies they will enter the information in Windows Form and the program automaticaly creates the WORD document under specific folder under application path. Once the empty word file created than ask user if they want...
25
2902
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with a utility developed by Tony Toews to handle the distribution and subsequent updates of the software. I'm having some trouble with the overall upgrade process I've implemented, and I'm hoping one of you may have an idea how to go about fixing...
2
3076
by: KA NMC | last post by:
Current application is built in VB.net 2005 what it does is open other small applications within the form. I'm not using mdi I probably should. Here is my problem The application load - main form only contains a menu strip - once selecting a menu option another form opens within the main form. What I want the app to do is; to check to make sure that the sub form is not already open. If it is bring it to front. My code.. I created a...
0
9695
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10902
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.