|
-
Aug 5th, 2004, 01:35 PM
#1
Thread Starter
Hyperactive Member
restricting multiple instances of child form?
I am using an MDI form with menu items.
I am using the following code to open a form when appropriate menu item is chosen. But I want to make sure if the user clicks on the same menu item multiple times, only one instance of the MDI child should be shown rather than mulitiple instance of the same (MDI child) form.
Dim NewMDIChild As New frmRateType
NewMDIChild.MdiParent = Me
NewMDIChild.StartPosition = FormStartPosition.CenterScreen
NewMDIChild.Show()
How can I restrict?
thanks
nath
-
Aug 5th, 2004, 01:44 PM
#2
Have a shared variable that determines if the form has already been instantiated (maybe a boolean or an integer if you want more than 1 but less than x instances).
In the constructor of the childform, query this variable and throw an exception if you already have enough instances.
Catch the exception in the calling sub.
I don't live here any more.
-
Aug 5th, 2004, 05:15 PM
#3
Thread Starter
Hyperactive Member
is there any alternate way to do this?
is there any alternate way to do this?
-
Aug 5th, 2004, 06:38 PM
#4
PowerPoster
Hi,
I have not yet tested this but see if the following helps:
In the Parent form load event
Public NewMDIChild as Form
Then in the Menu
NewMDIChild=Nothing
NewMDIChild = New frmRateType
NewMDIChild.MdiParent = Me
NewMDIChild.StartPosition = FormStartPosition.CenterScreen
NewMDIChild.Show()
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 5th, 2004, 06:52 PM
#5
Thread Starter
Hyperactive Member
-
Aug 5th, 2004, 06:55 PM
#6
PowerPoster
Hi,
Sorry, I should have said put the following in the General section of the Parent form:
Public NewMDIChild as Form
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 5th, 2004, 09:08 PM
#7
Frenzied Member
i agree with wossname. with that method, you can allow as many as you like if you ever feel the need later.
-
Aug 6th, 2004, 12:13 AM
#8
What about wossname's method isn't suitable for your program? It's the first thing I could think of when reading your question.
-
Aug 6th, 2004, 02:04 PM
#9
Addicted Member
Try this:
VB Code:
Dim f As frmRateType
Dim fTest As Form
For Each fTest In MDIForm.MdiChildren
If TypeOf fTest Is frmRateType Then
f = DirectCast(fTest, frmRateType)
'f now holds a reference to the first instance of
'frmRateType found in the MdiChildren collection
Exit For
End If
Next
If f Is Nothing Then
f = New frmRateType()
f.MdiParent = MDIForm
End If
f.Show()
f.Activate()
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
|