-
April 16th, 2013, 08:46 AM
#1
Unload All Modal Forms From The Parent
Hi All,
I've a very interesting situation. I use Visual Basic 6, I've four forms in my project. For Example Form1, Form2, Form3 and Form4.
In Form1 I've a Button that loads Form2:
Code:
Private Sub Command1_Click()
Form2.Show vbModal
End Sub
...And a timer that counts 10 secs:
Code:
Private Sub Timer3_Timer()
Timer3.Interval = 0
End Sub
From Form2 I Load Form3.... with .Show vbModal. And I open Form4 not Modal to Form1.
I need a Solution that, when the timer in Form1 enters Timer3_Timer() sub, the Forms That are modal opened(Form2 and Form3) to be Unloaded(Closed), And Form4 to remain Opened(Loaded)
If anyone have any Ideas...please share
Julian Dimitrov
-
April 16th, 2013, 09:51 AM
#2
Re: Unload All Modal Forms From The Parent
You have to have a way to know which forms you want to unload. I'm not aware of a way in VB6 to detect if a form is shown modally but you could always use the tag property or something like that.
Code:
Option Explicit
Private Sub Command1_Click()
Form2.Tag = "Modal"
Form2.Show 1
End Sub
Private Sub Timer1_Timer()
Dim frm As Form
For Each frm In Forms
If frm.Tag = "Modal" Then
Unload frm
End If
Next
End Sub
Last edited by DataMiser; April 16th, 2013 at 09:53 AM.
Always use [code][/code] tags when posting code.
-
April 16th, 2013, 02:48 PM
#3
Re: Unload All Modal Forms From The Parent
From the vault:
Code:
Dim AllowUnload As Boolean
Private Sub MDIForm_Load()
Form1.Show
Form2.Show
Form3.Show
End Sub
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
AllowUnload = True
End If
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
If AllowUnload Then
Exit Sub
End If
Cancel = True
AllowUnload = True
End Sub
Private Sub mnuClose_Click()
AllowUnload = False
Unload Me
End Sub
Private Sub mnuExit_Click()
AllowUnload = True
Unload Me
End Sub
-
April 17th, 2013, 12:34 AM
#4
Re: Unload All Modal Forms From The Parent
Thanks for the quick replay guys,
DataMiser: The approach is very clever, but in some forms, the .tag property is already taken with something else I'll figure it out somehow, with another variable. Anyways thanks for the idea.
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
|