我遇到了C#应用程序全屏模式的错误。单击全屏按钮进入和退出全屏模式时没有问题。当我使用F11时也一样,但是当我按下全屏按钮进入全屏模式并按F11退出时,它会退出全屏模式一毫秒左右,并立即返回全屏模式。谁知道解决方案?我使用的是Visual Studio 2012 Express。
我使用我的全屏幕按钮的代码:(名为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();
}
这是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;
}
}
答案 0 :(得分:2)
在这两种情况下,你都在打电话
WindowState = FormWindowState.Maximized;
这就是为什么你的窗口总是全屏显示的原因。在第二个代码块中,您应该删除该调用并将其保留到
WindowState = FormWindowState.Normal;