|
-
Aug 30th, 2005, 11:13 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] MDI question
How can i check if one of the child forms is already open as i dont want to create multiple instances of the same form
cheers
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 30th, 2005, 11:45 AM
#2
Re: MDI question
You can use something called Singletons. Only one instance of the class is allowed to exist.
http://www.codeproject.com/vb/net/Si...eton_Forms.asp
-
Aug 30th, 2005, 01:04 PM
#3
Frenzied Member
Re: MDI question
since the thread title is called MDI, then i will assume that you are talking about mdi child forms.
check my code for this issue , i use it in my mdi application
VB Code:
' this code should be written in the mdi parent form
dim frmx as new form1 'form1 is the name of the wanted form
Dim ctl As Form
For Each ctl In me.MdiChildren
If ctl.Name = FrmX.Name Then
ctl.BringToFront() : ctl.Show()
FrmX.Dispose()
Exit Sub
End If
Next
'Setting Parent
FrmX.MdiParent = me
i hope this will help
rgds
-
Aug 30th, 2005, 07:23 PM
#4
Re: MDI question
Assuming that the type of the MDI child is Form2, I would use something similar to maged but not quite the same:
VB Code:
Dim myChild As Form2
For Each frm As Form In Me.MdiChildren
If TypeOf frm Is Form2
myChild = frm
Exit For
End If
Next frm
If myChild Is Nothing Then
'Create a new child form.
myChild = New Form2
myChild.MdiParent = Me
myChild.Show()
Else
'Activate the existing child form.
myChild.Activate()
End If
Edit:
Having said that, the Singleton approach is definitely the more professional. It is actually not a bad idea to create a SingletonForm class that inherits the Form class and then derive all the forms you want to have this behaviour from that, instead of from Form as you usually would.
-
Aug 31st, 2005, 01:44 AM
#5
Frenzied Member
Re: MDI question
the advantage of your code is that u dont create an new instance of the form if it is not needed. for sure that is more effecient than creating a new form and then disposing it.
better code i must admit
-
Aug 31st, 2005, 03:05 AM
#6
Thread Starter
Fanatic Member
Re: MDI question
cool, cheers guys, first time doing a mdi app so will prob have more questions later
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
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
|