Reputation: 215
I'm experiencing a bug with the full screen mode of my C# application. There is no problem when I click the full screen button to go in and out of full screen mode. Same when I use F11, but when I press the full screen button to go into full screen mode and press F11 to go out of it, it goes out of full screen mode for a millisecond or so and goes back to full screen mode immediately. Anyone knows a solution? I use Visual Studio 2012 Express.
I use the fallowing code for my full screen button: (named b8)
if (FormBorderStyle != FormBorderStyle.None)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Normal;
WindowState = FormWindowState.Maximized;
p1.BackColor = Color.White;
p2.BackColor = Color.White;
TopMost = true;
b8.Image = null;
b8.Text = "-";
W.Select();
}
else
{
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Maximized;
if (Environment.OSVersion.Version.Build >= 7000)
{
if (DWM.DwmIsCompositionEnabled())
{
Color c = Color.FromArgb(255, 221, 220, 220);
TransparencyKey = c;
p1.BackColor = c;
p2.BackColor = c;
MARGINS mr = new MARGINS();
mr.T = 1800;
IntPtr h = Handle;
int result = DwmExtendFrameIntoClientArea(h, ref mr);
}
}
TopMost = false;
b8.Text = null;
b8.Image = MyApp.Properties.Resources.p;
W.Select();
}
And this one for F11:
if (y==(Keys.F11))
{
if (FormBorderStyle != FormBorderStyle.None)
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Normal;
WindowState = FormWindowState.Maximized;
p1.BackColor = Color.White;
p2.BackColor = Color.White;
TopMost = true;
b8.Image = null;
b8.Text = "-";
}
else
{
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Maximized;
if (Environment.OSVersion.Version.Build >= 7000)
{
if (DWM.DwmIsCompositionEnabled())
{
Color c = Color.FromArgb(255, 221, 220, 220);
TransparencyKey = c;
p1.BackColor = c;
p2.BackColor = c;
MARGINS mr = new MARGINS();
mr.T = 1800;
IntPtr h = Handle;
int result = DwmExtendFrameIntoClientArea(h, ref mr);
}
}
TopMost = false;
b8.Text = null;
b8.Image = MyApp.Properties.Resources.p;
}
}
Upvotes: 2
Views: 356
Reputation: 6026
In both cases you are calling
WindowState = FormWindowState.Maximized;
and that is why your window always goes to full screen. In your second code block, you should remove that call and just leave it to
WindowState = FormWindowState.Normal;
Upvotes: 3