Strange behaviour of Form.WindowState.Maximized in Form.Activate event

V

viliamb

Hi,

I am experiencing problem with changing the Form.WindowState property
of the Child form in the MDI Winform Application.

If I change the 'WindowState' property to
'Form.WindowState.Maximized ' in the Form Activate event of the MDI
child form I will get double Control/System menu box for this form. By
closing the form there is Control/System menu box left behind. If I
repeat the process the number of Control/System menu boxes grows.

I am expecting that each form can have only one Control/System menu
box.

Is this a defect or did I forget to take something into account? Is
there known hot fix for this behaviour e.g. another way to maximise MDI
child form in Activate Event?

I am using VS 2003, .NET 1.1 with SP1, PC is W2K with SP4.
Please see my demo below.

Thanks

Viliam Batka

PS: Regardless of unexpected visual effect it can indicates possible
memory leak.

//=DEMO==============================================
// Description:
// *Demo for Strange behaviour of FormWindowState.Maximized
// in Form.Activate event.
// *This C# example is possible to compile as console application
// with references to System.Windows.Forms.
// Author: Viliam Batka
using System;
using System.Windows.Forms;
namespace ViliamBatka.MdiTest
{
class MDI_Test
{
[STAThread]
static void Main(string[] args)
{
// create MDI main form
Form fMDI = new Form();
fMDI.Activated += new System.EventHandler(OpenMultipleChildren);
fMDI.IsMdiContainer=true;
Application.Run(fMDI);
}
// open multiple MDI childer
static void OpenMultipleChildren(Object sender, System.EventArgs e)
{
for (int i=1;i<10;i++)
{
Form fChild = new Form();
// add event handler
fChild.Activated += new System.EventHandler(Child_Activated);
fChild.MdiParent = (Form)sender;
fChild.Show();
fChild.WindowState = FormWindowState.Normal;
}
Form f = (Form)sender;
f.WindowState = FormWindowState.Maximized;
}

// maximize Child Form at Activate event
static void Child_Activated(Object sender, System.EventArgs e)
{
Form f = (Form)sender;
f.WindowState = FormWindowState.Maximized;
}
}
}
//=END DEMO=========================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top