MDI app - don't load document twice

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

How can I (in VB.Net 2005) check (when loading a file), to make sure if it's
already been loaded - then prompt the user to see if they really want to do
it (since it's already been loaded)?
 
Elmo Watson said:
How can I (in VB.Net 2005) check (when loading a file), to make sure if it's
already been loaded - then prompt the user to see if they really want to do
it (since it's already been loaded)?
what kind of file is that? or are you referring to an MDI child form?
 
The standard response is not to nform the user but just to bring the already
open file to the front or show it if it's hidden.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
OK - I understand that - but how do you do it ??

In vb6, you would iterate through the forms collection (For Each objForm In
Forms)

That's the first line - it got an error but didn't show me any of the
possible ways to change it...
 
add this method in your MDI form class

private void ShowForm(Type formType)
{
foreach (Form child in this.MdiChildren)
{
//if (formType.Name == child.Name)
if (formType.IsInstanceOfType(child))
{
child.Focus();
return;
}
}
Form frm = (Form)Activator.CreateInstance(formType);
frm.MdiParent = this;
frm.Show();
}

you can show your child form using ShowForm(typeof(YourChildFormClass))
 
The simplest way is to rely on the naming scheme of the documents. For
example when loadin a file the document will be called by the filename or
possibly just it's file name without the extension.

When a file load attempt is made, check all your existing loaded documents
to see if one of the same name exists, if it does, show it, if it doesn't
continue with the load.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
I've got a Property in my MDI form (DocName), which returns the ActiveMDI
file's document name (file loaded and showing in rtb). I'm still stumbling
around a bit

I'm using VB.Net (I couldn't translate from C# example given):
I've got :
the variable: 'filename' is the file I'm trying to load
Dim child as System.Windows.Forms.Form ' <-- don't know how to refer to the
DocName of each
For each Child in Me.MdiChildren
If CurrentForm.DocName = fileName Then ' <-- what do I need here, to
compare files?
blLoaded = True
Exit For
Else
blLoaded = False
End If
next

Can anyone help me finish here?
 
Back
Top