当前位置:网站首页>C# Winform 最大化遮挡任务栏和全屏显示问题
C# Winform 最大化遮挡任务栏和全屏显示问题
2022-06-24 19:49:00 【熊思宇】
在打开最大化窗体时,如果不进行配置,那么默认情况下窗体是被任务栏档住,导致有部分界面看不见,看看下面代码的效果,也许对你有帮助
新建一个Winform项目,添加三个按钮,给三个按钮添加点击事件

代码:
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)
{
//任务栏不会被遮挡
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.WindowState = FormWindowState.Maximized;
}
}
private void button2_Click(object sender, EventArgs e)
{
//任务栏会被遮挡
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)
{
//任务栏不会被遮挡
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;
}
}
}
}
效果:
点击按钮1,会最大化,但窗体不会遮挡任务栏,
点击按钮2,会全屏显示,
点击按钮3,会最大化,但窗体不会遮挡任务栏,
end
边栏推荐
- 【图数据库性能和场景测试利器LDBC SNB】系列一:数据生成器简介 & 应用于GES服务
- Investment analysis and prospect forecast report of global and Chinese triglycine sulfate industry from 2022 to 2028
- Andersen Global借助巴勒斯坦成员公司加强中东平台
- 水库大坝安全监测
- Phprunner 10.7.0 PHP code generator
- UE4 WebBrowser图表不能显示问题
- 5G dtu无线通信模块的电力应用
- Is there really something wrong with my behavior?
- 微搭低代码中实现增删改查
- Window system installation Nacos
猜你喜欢
随机推荐
美国众议院议员:数字美元将支持美元作为全球储备货币
Interesting checkbox counters
ArcGIS loads free online historical images as the base map (no plug-ins are required)
Classic interview questions and answers for embedded engineers
After 5 years of software testing in didi and ByteDance, it's too real
Requests Library
在滴滴和字节跳动干了 5年软件测试,太真实…
Go shopping
Hello C (IV) -- pointer and function
Hello C (two) -- use of bit operation
Today's sleep quality record 79 points
离散数学及其应用 2018-2019学年春夏学期期末考试 习题详解
第三代电力电子半导体:SiC MOSFET学习笔记(五)驱动电源调研
Analysis report on production and marketing demand and investment forecast of China's boron nitride industry from 2022 to 2028
What exactly is Nacos
Tiktok actual combat ~ sorting out the short video release process
企业级~uni-app网络请求封装
China CAE industry investment strategic planning and future development analysis report 2022 ~ 2028
Scala IO reads binary files
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181









