.NETGURU
loading forms only once.
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.upgrade.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

TerryW @vbssys.com>
I am trying to write my first app using dotnet after years of vb6.

I am trying to load a form from a "main" form but after I have loaded
one instance of the form's class I don't want to load any more. Do I
have to keep track of which classes I have instantiated or is there a
better way of doing this?

TIA
Terry W.
Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* TerryW <prog<NOSPAM>@vbssys.com> scripsit:
[Original message clipped]

You could implement the Singleton design pattern to provide only a
single instance:

Exploring the Singleton Design Pattern
<URL:http://msdn.microsoft.com/library/en-us/dnbda/html/singletondespatt.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Éric Moreau [VB MVP] (VIP)
A MDI application? In this case, you can iterate through the MdiChildren
collection to see if it is already in memory:

Private Function IsChildInMemory(ByVal pChildName As String) As Boolean

'A small method that checks to see if a particular form is currently
displayed as a child form

Dim frmChild As Form

For Each frmChild In Me.MdiChildren

If TypeName(frmChild).ToUpper = pChildName.ToUpper Then

frmChild.Activate()

Return True

End If

Next

Return False

End Function

Then, when you want to load a child, you can use it like this:

If Not IsChildInMemory("frmChild2") Then

Dim frm As New frmChild2

With frm

..MdiParent = Me

..Show()

'.Dock = DockStyle.Fill

End With

End If

--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)

"TerryW @vbssys.com>" <prog<NOSPAM> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Windows.Forms.DockStyle




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification