Question Minimizing Forms

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
Once again, I get hung up on the simple stuff...
Form1 instantiates Form2 which is a help screen for Form1. Form2 does not have a titlebar and most of the form is transparent as Form2 points out various features of Form1. I've included a couple of small clickable labels in Form2 so the user can close Form2 (just the Help screen) or minimize ALL of the forms in my app if they need to shift their attention to a different application. When I minimize Form1, the system closes Form2. I want Form2 to stay active so that when the app is maximized again, everything will be as it was when the user minimized it. Here is a simplifed case which consists of two forms that each have a clickable label. The label in Form1 instantiates Form2. The label in Form2 minimizes Form1.

VB.NET:
Public Class Form1

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Dim Frm As New Form2(Me)
        Frm.ShowDialog()
    End Sub
End Class

'----------------------------------------------------------------

Public Class Form2
    Dim Frm As Form

    Public Sub New(ByRef Frm As Form)
        InitializeComponent()
        Me.Frm = Frm
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Frm.WindowState = FormWindowState.Minimized
    End Sub
End Class

I'm having trouble understanding why Form2 gets closed when it's parent is minimized. 'Anybody have a cure or a workaround for this?
Thanx in advance...
 
Last edited:
When the following event is called and when the parent form is minimized

VB.NET:
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e  As                            System.EventArgs) Handles Label1.Click
        Frm.WindowState = FormWindowState.Minimized
End Sub

the handle of Form2 is destroyed (rather changes, Not pretty sure) thus the closing event of form2 is invoked.

Solution to this is rather than making it Modal make it non modal.

Change Frm.ShowDialog() to Frm.Show()

Krsh
 
One reason that I don't want to do that is;
I need to prevent any user interaction with Form1 while Form2 is active. By making Form2 modal, it saves a world of coding in Form1 (determining if Form2 is active) in every control on Form1... And there are many. Right now, I'm just minimizing Form2 and hiding Form1 when the minimize label is clicked. This works but it creates a lot of activity in the Taskbar as Form2 initially adds a window to the taskbar. Then when minimized, Form1 disappears from the taskbar and Form2 slides over. Then, when maximized, Form1's taskbar window reappears. I know it's trivial, but it makes the application look like it was created by an amateur; (which it is... but it doesn't need to be so obvious). So, what I'd really like to do is to replace Form1's window in the taskbar with Form2's as soon as Form2 is instantiated. That way there would always be just one window in the taskbar. Is there a way to get rid of the window in the taskbar (Form1) AFTER the form has been created with the "Shown in Taskbar" property set to TRUE?
 
Yup you can remove it from displaying it from the taskbar by overriding the CreateParams property of Form2 and Set the ExStyle property to

Dim oPar As CreateParams = MyBase.CreateParams
oPar.ExStyle = &H80L

Krsh
 
ALX, your "help form" is a typical "ToolWindow", which has default support in UI design and behaviour. Tool windows minimize/restore/close automatically with main form and always stay on top of the owner. To set this up you should set your help form as an owned form of the main, use code like helpform.Owner = Me or Me.AddOwnedForm(helpform). There is also two default border styles available for forms (FixedToolWindow and SizableToolWindow) that helps user identify this typical UI element. The helpform should also have its ShowInTaskbar property set to False.
 
Back
Top