"FormWindowState.Maximized" doesn't force maximize but "FormBorderStyle.None" does?

N

nzpcmad

I enclose a simple application to show this using SP2.

Note that both Form1 and Form2 have

this.WindowState = FormWindowState.Maximized;

set in the On_Load event.

Start the application. Leave the check-box unchecked. Toggling between
the two screens causes the forms to be minimized on the toolbar and
you have to click on the toolbar in order to maximize them. The "Show
Desktop" icon on the toolbar works here.

Now check the checkbox. This forces

this.FormBorderStyle = FormBorderStyle.None;

in the On_Load event.

Toggling between the forms shows that the forms are always maximized
which is the desired outcome. However, in this state the "Show
Desktop" icon on the toolbar does not work any more.

Can anyone shed some light on this?

Thanks

---------------------------------------------------------------
Form1

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace BugDem
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button1;

public static bool formBorderStyleNone;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

if (formBorderStyleNone)
checkBox1.Checked = true;

//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.checkBox1 = new System.Windows.Forms.CheckBox();
//
// button1
//
this.button1.Location = new System.Drawing.Point(81, 64);
this.button1.Text = "Next form";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(29, 152);
this.checkBox1.Size = new System.Drawing.Size(176, 20);
this.checkBox1.Text = "Set FormBorderStyle.None";
this.checkBox1.CheckStateChanged += new
System.EventHandler(this.checkBox1_CheckStateChanged);
//
// Form1
//
this.BackColor = System.Drawing.Color.Khaki;
this.ClientSize = new System.Drawing.Size(234, 268);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Text = "BugDem";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>

static void Main()
{
Application.Run(new Form1 ());
}

private void Form1_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Maximized;

if (checkBox1.Checked)
{
this.FormBorderStyle = FormBorderStyle.None;
formBorderStyleNone = true;
}
else
formBorderStyleNone = false;
}

private void button1_Click(object sender, System.EventArgs e)
{
this.Hide ();
Form next = new Form2 ();
next.Show ();
}

private void checkBox1_CheckStateChanged(object sender,
System.EventArgs e)
{
if (checkBox1.Checked)
formBorderStyleNone = true;
else
formBorderStyleNone = false;
}
}
}

----------------------------------------------------
Form2

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace BugDem
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;

public Form2()
{
//
// Required for Windows Form Designer support
//

InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new System.Drawing.Point(65, 64);
this.button1.Size = new System.Drawing.Size(104, 20);
this.button1.Text = "Previous form";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.BackColor = System.Drawing.Color.DarkKhaki;
this.ClientSize = new System.Drawing.Size(234, 268);
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Text = "BugDem2";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form2_Load);

}
#endregion

private void Form2_Load(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Maximized;

if (BugDem.Form1.formBorderStyleNone)
{
this.FormBorderStyle = FormBorderStyle.None;
}
}

private void button1_Click(object sender, System.EventArgs e)
{
this.Hide ();
Form back = new Form1 ();
back.Show ();

}
}
}
 

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