Unload All Modal Forms From The Parent
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Unload All Modal Forms From The Parent

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    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

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,850

    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 10:53 AM.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Apr 2013
    Posts
    2

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center