C# - Why won't a fullscreen winform app ALWAYS cover the taskbar?

后端 未结 5 563
名媛妹妹
名媛妹妹 2020-12-31 01:45

I\'m using Windows Vista and C#.net 3.5, but I had my friend run the program on XP and has the same problem.

So I have a C# program that I have running in the backgr

相关标签:
5条回答
  • 2020-12-31 02:02

    Try this (where this is your form):

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

    That'll set the form to fullscreen, and it'll cover the taskbar.

    0 讨论(0)
  • 2020-12-31 02:07
    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();
            }
    }
    
    0 讨论(0)
  • 2020-12-31 02:13

    As far as I know, the taskbar is either above or below windows based on the "Keep the taskbar on top of other windows" setting. (At least, that's the wording in XP.) I suppose you could try to see if you can detect this setting and toggle it if needed?

    0 讨论(0)
  • 2020-12-31 02:17

    I've tried so many solutions, some of them works on Windows XP and all of them did NOT work on Windows 7. After all I write a simple method to do so.

    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;
            }
        }
    

    the order of code is important and will not work if you change the place of WindwosState and FormBorderStyle.

    One of the advantages of this method is leaving the TOPMOST on false that allow other forms to come over the main form.

    It absolutely solved my problem.

    0 讨论(0)
  • 2020-12-31 02:17

    Try resizing the form and bringing it to the front of the z-order like so:

            Rectangle screenRect = Screen.GetBounds(this);
            this.Location = screenRect.Location;
            this.Size = screenRect.Size;
            this.BringToFront();
    
    0 讨论(0)
提交回复
热议问题