473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2923
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.ShowDialog() != DialogResult.OK)
return;

string ext = Path.GetExtension(dlgFileOpen.FileName);
if (ext.ToUpper().CompareTo(".JPG") == 0)
{
PictureForm.Load(dlgFileOpen.FileName);
PictureForm.Show();
}
else if (ext.ToUpper().CompareTo(".TXT") == 0)
{
TextEditor.Load(dlgFileOpen.FileName);
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.CompareTo(m_FileName) == 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
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...
55
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...
1
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...
2
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...
6
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...
3
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...
7
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...
0
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...
25
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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...

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.