473,413 Members | 1,778 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,413 software developers and data experts.

Checking for existing instance of a form

I am very accustomed to VB6 and therefore the OOP characteristics of
VB.Net are giving me some difficulties. How can I ensure that only one
instance of a form is created (I am using MDI Parent and Child forms).
I only want the user to be able to have one window open at a time within
the MDI Client. I thought the easy way would be to disable the toolbar
used to call the other forms but have not figured out that yet. Is
there a better way to ensure only one instance is created?

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
2 3083
Hi Ivan,

Here's something to give you ideas.

Regards,
Fergus

<code status="untested">
Private Sub MnuFooBar_Click(....) Handles MnuFooBar.Click
CreateOrActivateForm ("FooBar!!", GetType (frmFooBar))
End Sub

Private Sub CreateOrActivateForm _
(sHeading As String, oFormType As Type)
Dim oForm As Form
'Exit if we already have this form...
For Each oForm In Me.MdiChildren
If oForm.Name = sHeading Then
oForm.Activate
Return
End If
Next

' Not found ... Let's create it.
oForm = New Activator.CreateInstance (oFormType)
oForm.MdiParent = Me
oForm.Show()
End Sub
</code>
Nov 20 '05 #2
* Ivan Weiss <iv*****@optonline.net> scripsit:
I am very accustomed to VB6 and therefore the OOP characteristics of
VB.Net are giving me some difficulties. How can I ensure that only one
instance of a form is created (I am using MDI Parent and Child forms).
I only want the user to be able to have one window open at a time within
the MDI Client. I thought the easy way would be to disable the toolbar
used to call the other forms but have not figured out that yet. Is
there a better way to ensure only one instance is created?


<http://groups.google.de/groups?selm=u5iBdcHRDHA.1552%40TK2MSFTNGP10.phx.gb l>

As an alternative your child form can implement the Singleton design
pattern.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
Nov 20 '05 #3

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

Similar topics

5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
0
by: Larry Lau | last post by:
Hi, I would like to know if it is possible to launch a new browser instance from an existing browser instance with a separated newly created session. window.open(url) already keep you in the...
1
by: Paul Bromley | last post by:
Please help with this one - I have scoured the newsgroups for information on this, and all of the responses relate to how to refernce controls on a NEW instanc of a form and not an exitsing one. I...
5
by: RSH | last post by:
I am using code to create a new modal form from a parent form. It is not an MDI form. I need to know if an instance of the form already exists so when the user clicks on the button I can close...
5
by: tarnap | last post by:
Hello, I have an instance of a form, lets say formA. This form is passed to a method that must create a new form, lets say formB of the same type. How can this be accomplished except by using...
2
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
14
by: SimeonD | last post by:
Hi I have an access database called Sales.Mdb In vb.net 2005, I'd like to open it. Which I can do. What I can't figure out is how to figure out if Sales.Mdb is open already. If so, I want to open...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.