|
-
Dec 18th, 2002, 01:32 PM
#1
Thread Starter
Hyperactive Member
Dont Show Form Twice..
Hey guys/gals I have a MDI form that will display and Inventory form if you select a button from the toolbar...
Here is the problem...
If you hit the button twice it will create a second form.. How can I stop that?
Code:
Case 1
Dim NewMDIChild As New frmInventory()
'Set the Parent Form of the Child window.
NewMDIChild.MDIParent = Me
'Display the new form.
NewMDIChild.Show()
Case 2
etc etc etc
Thanks in advance...
Anjari
Last edited by Anjari; Dec 18th, 2002 at 05:00 PM.
-
Dec 18th, 2002, 01:51 PM
#2
Sleep mode
how many forms do you want to have?fixed numbers ??
-
Dec 18th, 2002, 01:54 PM
#3
Thread Starter
Hyperactive Member
...
well i will have multiple forms.. Just not the same type..
I guess what i could do is disable the button... but what I would like to do is keep it active and when pused the second time while the form is open bring that form to the front...
Thanks,
Anjari
-
Dec 18th, 2002, 02:06 PM
#4
You just have to store the instance that you make and then on other attempts check if it is Nothing. If it is nothing then make a new one otherwise just show the same instance.
-
Dec 18th, 2002, 02:09 PM
#5
VB Code:
'with form level scope
Dim fInventory as frmInventory
'in your code
Case 1
If fInventory Is Nothing Then
fInventory=New frmInventory
fInventory.MDIParent = Me
End If
'Display the new form.
fInventory.Show()
Case 2
-
Dec 18th, 2002, 03:42 PM
#6
Thread Starter
Hyperactive Member
ok here is what i did....
In a Module I put this:
Public InventoryFormOpen As Boolean = False
On my Main form Toolbar I put:
Case 5
If InventoryFormOpen = False Then
Dim NewMDIChild As New frmInventory()
'Set the Parent Form of the Child window.
NewMDIChild.MDIParent = Me
'Display the new form.
NewMDIChild.Show()
Else
End If
Then for my Inventory Form I placed:
Private Sub frmInventory_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
InventoryFormOpen = True
End Sub
Private Sub frmInventory_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
InventoryFormOpen = False
End Sub
This has apparently kept my Form from showing twice... I am still new to VB and I am sure this is not the "proper way" but hey like I said it works...
The only thing I need to figure out is to make that form the focus form it other forms are open and the toolbar button is pushed....
thats why I have the "Else" area...
Take Care,
Anjari
-
Dec 18th, 2002, 05:02 PM
#7
Thread Starter
Hyperactive Member
Sigh
Now what happens:
When you select a button on the toolbar it wont show the same form twice but if you select another button it WILL keep displaying that form over and over.... and vice versa....
anyone out there that can help?
Thanks,
Anjari
-
Dec 19th, 2002, 02:05 AM
#8
Registered User
There are various ways to deal with this I guess. I also wanted to show only one instance of each form at the most in one of my apps, but also if that button was hit I instead wanted to activate the form if there was one open in the background. So I did like this....
Code:
Dim frm As Form
For Each frm In Me.MdiChildren
If frm.GetType Is GetType(InventoryForm) Then
frm.Activate()
Exit Sub
End If
Next
frm = New InventoryForm()
With frm
.MdiParent = Me
.WindowState = FormWindowState.Maximized
.Show()
End With
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
|