当前位置:网站首页>C WinForm maximizes occlusion of the taskbar and full screen display

C WinForm maximizes occlusion of the taskbar and full screen display

2022-06-25 00:07:00 Xiongsiyu

When you open the maximized form , If not configured , By default, the form is blocked by the taskbar , Some interfaces are invisible , See the effect of the following code , It may help you

Create a new one Winform project , Add three buttons , Add a click event to the three buttons

Code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private Size WindowMaximumSize;

        private void Form1_Load(object sender, EventArgs e)
        {
            WindowMaximumSize = this.MaximumSize;
            this.TopMost = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // The taskbar will not be blocked 
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.WindowState = FormWindowState.Maximized;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // The taskbar will be blocked 
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.None;
                this.MaximumSize = WindowMaximumSize;
                this.WindowState = FormWindowState.Maximized;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // The taskbar will not be blocked 
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.WindowState = FormWindowState.Normal;
            }
            else
            {
                this.FormBorderStyle = FormBorderStyle.FixedSingle;
                this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
                this.WindowState = FormWindowState.Maximized;
            }
        }

    }
}

effect :

Click button 1, Will maximize , But the form does not obscure the taskbar ,

Click button 2, It will be displayed in full screen ,

Click button 3, Will maximize , But the form does not obscure the taskbar ,

end

原网站

版权声明
本文为[Xiongsiyu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206241929009702.html