首页 文章

C# - 为什么全屏winform应用程序永远不会覆盖任务栏?

提问于
浏览
21

我使用的是Windows Vista和C#.net 3.5,但我让我的朋友在XP上运行程序并遇到同样的问题 .

所以我有一个C#程序,我在后台运行,在SystemTray中有一个图标 . 我有一个低级键盘钩,所以当我按下两个键(在这种情况下为Ctr窗口)时,它将拉动应用程序的主窗体 . 在组合键按下甚至处理程序中将表单设置为全屏:

this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

所以它基本上有效 . 当我点击CTR Windows时,无论我关注哪个程序,它都会显示该表单 . 但有时候,任务栏仍然会显示在我不想要的表单上 . 当我按下那个键组合时,我希望它始终是全屏的 .

我认为这与应用程序最初关注的内容有关 . 但即使我点击我的主表单,任务栏有时也会停留在那里 . 所以我想知道焦点是否真的是问题 . 看起来有时候任务栏很顽固,并且不想坐在我的程序后面 .

任何人有任何想法如何解决这个问题?

编辑:更多详细信息 - 当您将其置于全屏模式或将powerpoint置于演示模式时,我试图获得与Web浏览器相同的效果 .

在Windows窗体中,您可以将边框样式设置为none并最大化窗口 . 但有时窗口不会出于某种原因覆盖任务栏 . 一半的时间 .

如果我将主窗口放在最顶层,那么当我点击它时其他窗口会落在它后面,如果任务栏被隐藏,我不想要它 .

5 回答

  • 0

    试试这个(其中 this 是你的表格):

    this.Bounds = Screen.PrimaryScreen.Bounds;
    this.TopMost = true;
    

    这会将表单设置为全屏,它将覆盖任务栏 .

  • 0

    我已经尝试了很多解决方案,其中一些解决方案适用于Windows XP,而且所有解决方案都无法在Windows 7上运行 . 毕竟我写了一个简单的方法来实现 .

    private void GoFullscreen(bool fullscreen)
        {
            if (fullscreen)
            {
                this.WindowState = FormWindowState.Normal;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.Bounds = Screen.PrimaryScreen.Bounds;
            }
            else
            {
                this.WindowState = FormWindowState.Maximized;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
            }
        }
    

    代码的顺序很重要,如果你改变WindwosState和FormBorderStyle的位置将无法工作 .

    这种方法的一个优点是使TOPMOST处于假状态,允许其他形式通过主窗体 .

    它绝对解决了我的问题 .

  • 18
    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F11)
            if (FormBorderStyle == FormBorderStyle.None)
            {
                FormBorderStyle = FormBorderStyle.Sizable;
                WindowState = FormWindowState.Normal;
            }
            else
            {
                SuspendLayout();
                FormBorderStyle = FormBorderStyle.None;
                WindowState = FormWindowState.Maximized;
                ResumeLayout();
            }
    }
    
  • 1

    据我所知,任务栏位于窗口的上方或下方,基于“将任务栏保留在其他窗口之上”设置 . (至少,这是XP中的措辞 . )我想你可以尝试看看你是否可以检测到这个设置并在需要时进行切换?

  • 2

    尝试调整表单的大小并将其带到z顺序的前面,如下所示:

    Rectangle screenRect = Screen.GetBounds(this);
            this.Location = screenRect.Location;
            this.Size = screenRect.Size;
            this.BringToFront();
    

相关问题