Lost in resize maze

I have a module that calls a non-modal form that calls a modal form that calls another modal form.
I want to find a way to minimize all forms when one of 'em got minimized.
(I.E: minimize form2 and form1 when form2 is minimized (form2 is modal); minimize form3, form2 and form1 when form3 is minimized (form3 is modal too)).
No need to mention I want a way to get 'em back on screen when the user press the minimized application button! :)
(Don't want you guys to show me the one-way mess; I'm already an expert at it! lol)

thanks!
SylvaniaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
Try this example:

First create a new project and add 3 forms to it:  Form1, Form2, Form3

Then add the following code to the DECLARATIONS SECTION of Form1:

     Private Sub Form_Click()
         Form2.Show 1
     End Sub
     Private Sub Form_Load()
         Form1.Height = 3600
         Form1.Width = 3600
     End Sub


Add the following code to the DECLARATIONS SECTION of Form2:

     Private Sub Form_Click()
         Form3.Show 1
     End Sub
     Private Sub Form_Load()
         Form2.Height = Form1.Height
         Form2.Width = Form1.Width
         Form2.Top = Form1.Top + 600
         Form2.Left = Form1.Left + 600
     End Sub


Add the following code to the DECLARATIONS SECTION of Form3:

     Public mmSwitch As Boolean
     Private Sub Form_Load()
         mmSwitch = False
         Form3.Height = Form2.Height
         Form3.Width = Form2.Width
         Form3.Top = Form2.Top + 600
         Form3.Left = Form2.Left + 600
     End Sub
     Private Sub Form_Resize()
     If mmSwitch = False Then
         mmSwitch = True
     Else
         If Form3.WindowState = vbMinimized Then
             Form1.WindowState = vbMinimized
             Form2.WindowState = vbMinimized
         Else
             Form1.WindowState = vbNormal
             Form2.WindowState = vbNormal
         End If
     End If
     End Sub



Then run the program...  Form1 will show non-modally.
Click on Form1 and Form2 will show modally.
Click on Form2 and Form3 will show modally.
Now for the kicker... MINIMIZE Form3 and Form1, Form2, and Form3 will minimize.
Now double-click Form3 and all of the forms will reappear!

The "secret" is the public variable mmSwitch on Form3, and the code in the Form_Resize event of form3. Don't forget to set mmSwitch = False when you unload form3...



Cheers!
0
 
mark2150Commented:
You can't have a modal form calling another modal form. You can only have one modal form on the screen at a time.

you can't minimize a modal form.

M
0
 
SylvaniaAuthor Commented:
But, like I said, my non-modal main form calls a modal form (with show 1) and then, this form calls another modal form (with show 1).
If it is what I wouldn't be able to do, please, explain me what is happening, since the 3 forms are clearly visible at the same time. (and I can't click on either).
(I just can't dare to contradict such an expert as you, Mark... I just can conclude I didn't understand your comment, or there is something I don't get)
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AnswerTheManCommented:
A Modal form *CAN* call another MODAL form.
what it can't call is a NON=MODAL form.

that's why althoght you have 3 forms on screen - you still in a maze.
whenever you try to minimize Form3 (the Current MODAL FORM) - he should be calling form1 which is NON-MODAL to minimize - can't do that.
if you want to work it around -  use API
SetForegroundWindow and GetForegroundWindow with NON mODAL FORMS. use the UnloadState of Form_QueryUnload and the form's control boxes, along with Booleans in a Module to achive your goal.
0
 
SylvaniaAuthor Commented:
McRider,
I have no idea why your code works, and not mine...
You see: with my code (wich looks A LOT like yours), all 3 windows get minimized in the TASKBAR, and become impossible to resize anymore, since the one showed in taskbar is form1 (wich cannot be targeted due to the 2 modal forms that sit over it)
But, with your code, the topmost form minimize ABOVE the taskbar, in the bottom-left corner...
It's rather ugly, but it works!
I thank you...
I'll give you your points, but I want you to tell me if you know a way to have it works with no form on TOP of the taskbar...
(I'll give you the points after your next comment, whatever it is)

thanks again!
0
 
mcriderCommented:
This is why Form3 in my example will only minimize to above the taskbar and not show up in the taskbar...

PRB: Modal Form Does Not Appear in the Taskbar
http://support.microsoft.com/support/kb/articles/Q178/7/54.ASP 
 
It has to minimize to "someplace" and that's where microsot decided to put it.


(Hoping this deserves to be graded as an "A"...)


Cheers!
0
 
SylvaniaAuthor Commented:
McRider...
Just for fun, did you try your code with form1, form2, form3 AND form4 instead? (repeat the same scenario, but having these 4 forms to minimize, the latter 3 being modal!??)
Did you try with TWO forms (form1 beging non-modal, and form2 begin modal??
Did you actually try the code with any number of forms other than 1 or 3??
I don't know if you'll experiment what I have, but it's kinda scary... Do you understand? Can you help me?

If you're unable to help me, I'll accept your answer, since it's what I formerly stated.
But I hope you'll be able to help me, since the code you gave me only works for the magic number of forms "3"...

*scary soundtrack*

thanks!
0
 
mcriderCommented:
I never had a need to nest more than 3 forms... BUT GOD THATS BIZZARE!!!

I have no idea...


Cheers!
0
 
SylvaniaAuthor Commented:
Ok, but, did you try with TWO forms!?
(a non-modal form calling a modal form?)
0
 
mcriderCommented:
Ok, try this on the modal form...

Public mmSwitch As Boolean
     Private Sub Form_Load()
         mmSwitch = False
     End Sub
Private Sub Form_Resize()
If mmSwitch = False Then
    mmSwitch = True
Else
    If Form2.WindowState = vbMinimized Then
       Form1.Tag = CStr(Form1.Top)
       Form1.Top = Screen.Height + 600
    Else
       Form1.Top = CLng(Form1.Tag)
    End If
End If
End Sub



Cheers!
0
 
mcriderCommented:
By the way, the above code doesn't really minimize the non-modal form... It just moves it off the screen so you can't see it, and put's it back when the modal form is normalized...

actually, the definition of mmSwitch should be private... and you should use a different private variable for each form...


Cheers!
0
 
RejojohnyCommented:
there is no need for that lengthy procedure of defining public varibles in eah form and checking them.. try this .. it works

I have 2 forms frmMainForm and frmChildForm... frmMainForm calls the childform modally

frmMainForm has a command button called cmdShowChildForm to open child form modally
-------------------------------------- code for frmMainForm
Option Explicit

Private Sub cmdShowchildForm_Click()
    frmChildForm.Show vbModal
End Sub

Private Sub Form_Resize()
    Dim lfrmForm As Form
    If Me.WindowState <> vbMinimized Then
        For Each lfrmForm In Forms
            If lfrmForm.Name = "frmChildForm" Then
                frmChildForm.Show vbModal
                Exit Sub
            End If
        Next
    End If
End Sub
----------------------------------

--------------------------- code for frmChildForm --------------------
Option Explicit

Private Sub Command1_Click()
    Me.WindowState = vbMinimized
End Sub

Private Sub Form_Resize()
    If WindowState = vbMinimized Then
        Me.Hide
        Me.WindowState = vbNormal
        frmMainForm.WindowState = vbMinimized
    End If
End Sub
-------------------------------------------------------------------
0
 
RejojohnyCommented:
sorry posted here by mistake .. was supposed to be in
Visual_Basic/Q_20885944.html
0
All Courses

From novice to tech pro — start learning today.