full screen mode, but don't cover the taskbar

前端 未结 10 1295
旧巷少年郎
旧巷少年郎 2020-12-05 19:38

I have a WinForms application, which is set to full screen mode when I login.

My problem is it\'s covering the Windows taskbar also. I don\'t want my application to

相关标签:
10条回答
  • 2020-12-05 20:28

    I'm not good at explaining but this is the code I used to maximize or to full screen the winforms which would not cover up the taskbar. Hope it helps. ^^

    private void Form_Load(object sender, EventArgs e)
    {
        this.Height = Screen.PrimaryScreen.WorkingArea.Height;
        this.Width = Screen.PrimaryScreen.WorkingArea.Width;
        this.Location = Screen.PrimaryScreen.WorkingArea.Location;
    }
    
    0 讨论(0)
  • 2020-12-05 20:29

    Try without FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; and comment line like :

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1_Load( object sender, EventArgs e )
        {
            // FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            Left = Top = 0;
            Width = Screen.PrimaryScreen.WorkingArea.Width;
            Height = Screen.PrimaryScreen.WorkingArea.Height;
        }
    }
    
    0 讨论(0)
  • 2020-12-05 20:32

    If Maximizing isn't what you're looking for, then you'll need to calculate the window size yourself by checking for the location and size of the taskbar:

    find-out-size-and-position-of-the-taskbar

    0 讨论(0)
  • 2020-12-05 20:33

    Arcanox's answer is great for a single monitor, but if you try it on any screen other than the leftmost, it will just make the form disappear. I used the following code instead.

    var workingArea = Screen.FromHandle(Handle).WorkingArea;
    MaximizedBounds =  new Rectangle(0, 0, workingArea.Width, workingArea.Height);
    WindowState = FormWindowState.Maximized;
    

    The only difference is I'm overriding the top & left values to be 0, 0 since they will be different on other screens.

    0 讨论(0)
提交回复
热议问题