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
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
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
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.