|
-
Jan 16th, 2008, 04:29 PM
#1
Thread Starter
Frenzied Member
Modal Form
The start-up Form in a VB6 app is Form1. This Form has a TreeView. When any node in the TreeView is right-clicked, a menu pops-up. Clicking a menu item opens another Form named Form2 which should be a modal Form. Users can open multiple instances of Form1. This is how I am invoking Form2:
Code:
Form1:
Private Sub mnuTV_Click()
Dim frm As Form2
Set frm = New Form2
If Not (TreeView1.SelectedItem Is Nothing) Then
Call frm.ShowMe(Me, TreeView1.SelectedItem)
End If
End Sub
Form2:
Private frmOwner As Form
Public Sub ShowMe(OwnerForm As Form, TNode As MSComctlLib.Node)
Set frmOwner = OwnerForm
Me.Show vbModeless, frmOwner
frmOwner.Enabled = False
Call GetTVNodeSelected(TNode)
End Sub
Sub GetTVNodeSelected(Node As MSComctlLib.Node)
Dim str1 As String
Dim str2 As String
str1 = Node.Text
str2 = Node.Tag
'more code here
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
frmOwner.Enabled = True
Unload Me
End Sub
The reason I am not using the code
to invoke Form2 (in the mnuTV_Click() sub) in Form1 is because since users can open multiple instances of Form1 (which means multiple TreeViews can be visible at the same time), assuming that 2 instances of Form1 are open, when Form2 is invoked in any of the 2 instances, it will act as a modal window for both the instances of Form1 instead of being a modal window for only that instance of Form1 from which Form2 has been invoked.
But under some conditions I find that even though all instances of Form1 & Form2 are closed, the app doesn't unload completely. An instance of Form1 still continues running & its icon in the Taskbar still exists.
How do I ensure that when all instances of Form1[ & Form2 are closed, the entire app gets unloaded?
Note that this doesn't happen always; only sometimes. I couldn't unearth under what circumstances does this happen. Moreover, if Form2 is never invoked & multiple instances of Form1 are open, then closing each instance of Form1 unloads the app completely. This happens only when Form2 is invoked; so I guess it is Form2 which doesn't unload itself even after all instances of Form1 & Form2 have been closed.
ARPAN
IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!
NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!
PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?
-
Jan 16th, 2008, 07:06 PM
#2
Re: Modal Form
How about unloading all forms on exit of the main form?
Dim i As Integer
For i = Forms.count - 1 To 0 Step -1
Unload Forms(i)
Next i
-
Jan 16th, 2008, 07:18 PM
#3
Thread Starter
Frenzied Member
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
|