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

Prevent more than one instance from loading.

Hi Everyone,
I'm looking for a way to make sure that only one instance of a form is
loaded. I have tried the following:
Private Sub mnuPatients_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPatients.Click
try
if not ifrmPatients is nothing then
exit Sub
End If
cursor = cursors.WaitCursor
ifrmPatients = new frmPatients
ifrmPatients.MdiParent = me
ifrmPatients.Show
cursor = cursors.Default
Catch ex As Exception
msgbox(ex.Message )
End try
End Sub

That didn't seem to work by itself. In the Closed event of the child forms
I even tried to force a Dispose, but that don't seem to get rid of the
reference. ANy ideas.
THanks.
Michael
Nov 21 '05 #1
2 1240
Hi,

I usually add a definstance property of a form if I only want
one instance of the form. I would call Form1.DefInstance.Show to display
the form.
Add to the forms new procedure

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frm = Me
End Sub

Add to the forms dispose procedure

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
frm = Nothing
MyBase.Dispose(disposing)
End Sub
Add the following code to the form

Private Shared frm As Form1

Public Shared ReadOnly Property DefInstance() As Form1
Get
If frm Is Nothing Then frm = New Form1
Return frm
End Get
End Property

Ken
--------------------
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi Everyone,
I'm looking for a way to make sure that only one instance of a form is
loaded. I have tried the following:
Private Sub mnuPatients_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPatients.Click
try
if not ifrmPatients is nothing then
exit Sub
End If
cursor = cursors.WaitCursor
ifrmPatients = new frmPatients
ifrmPatients.MdiParent = me
ifrmPatients.Show
cursor = cursors.Default
Catch ex As Exception
msgbox(ex.Message )
End try
End Sub

That didn't seem to work by itself. In the Closed event of the child
forms
I even tried to force a Dispose, but that don't seem to get rid of the
reference. ANy ideas.
THanks.
Michael

Nov 21 '05 #2
Hi Ken,
Thank you so much for your help. That did the job. I found other tips to do
the same thing, but could not get them to work right. But this one did it.
Thanks again.
Michael

"Ken Tucker [MVP]" wrote:
Hi,

I usually add a definstance property of a form if I only want
one instance of the form. I would call Form1.DefInstance.Show to display
the form.
Add to the forms new procedure

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
frm = Me
End Sub

Add to the forms dispose procedure

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
frm = Nothing
MyBase.Dispose(disposing)
End Sub
Add the following code to the form

Private Shared frm As Form1

Public Shared ReadOnly Property DefInstance() As Form1
Get
If frm Is Nothing Then frm = New Form1
Return frm
End Get
End Property

Ken
--------------------
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi Everyone,
I'm looking for a way to make sure that only one instance of a form is
loaded. I have tried the following:
Private Sub mnuPatients_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPatients.Click
try
if not ifrmPatients is nothing then
exit Sub
End If
cursor = cursors.WaitCursor
ifrmPatients = new frmPatients
ifrmPatients.MdiParent = me
ifrmPatients.Show
cursor = cursors.Default
Catch ex As Exception
msgbox(ex.Message )
End try
End Sub

That didn't seem to work by itself. In the Closed event of the child
forms
I even tried to force a Dispose, but that don't seem to get rid of the
reference. ANy ideas.
THanks.
Michael


Nov 21 '05 #3

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

Similar topics

9
by: Felix Wiemann | last post by:
Sometimes (but not always) the __new__ method of one of my classes returns an *existing* instance of the class. However, when it does that, the __init__ method of the existing instance is called...
2
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely...
25
by: Dave Turner | last post by:
I know that its impossible to completely prevent somebody from ripping a site (or cracking software) if that person has the skills and the time/patience, but there are tricks that can be employed...
7
by: Daylor | last post by:
how to prevent application to run more than one instance ?
2
by: Totto | last post by:
Hi How do I prevent a program from beeing started more than one time. IE. If a dot net app is already started how do I prevent a second instance to be started ? Tnx Totto
4
by: Rich | last post by:
Hello, my app opens a 2nd form (form2) by clicking a button on the first form (form1). I do not want to open form2 in modal form, but I only want one instance of form2 open. So if someone...
7
by: Garry Jones | last post by:
I have a website consisting of php segments. Example page1.html calls in code from seg1.php and seg2.php If the user goes directly to www.mydomain.com/seg1.php they see everything visible to...
3
by: Phil | last post by:
Jerry posed some good ideas, a while back, on website a security issue that comes up often. Gary Jones was asking how to keep users from directly accessing php pages, out of sequence. Jerry...
6
by: Arthur Dent | last post by:
Anyone know, in VB.NET (2005) how to prevent duplicate occurrences of the same event handler on an event? e.g... I have some object which raises an event, and some other class which consumes...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.