1

我的 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;
            }
        }          
4

1 回答 1

2

在这两种情况下,您都在打电话

WindowState = FormWindowState.Maximized;

这就是为什么您的窗口总是全屏显示的原因。在您的第二个代码块中,您应该删除该调用并将其留给

WindowState = FormWindowState.Normal;
于 2013-07-12T19:40:01.587 回答