当前位置:网站首页>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
边栏推荐
猜你喜欢

VR全景制作的优势是什么?为什么能得到青睐?

Is there really something wrong with my behavior?

Tremblement de terre réel ~ projet associé unicloud

抖音实战~发布短视频流程梳理

水库大坝安全监测

canvas线条的动态效果

JPA learning 2 - core annotation, annotation addition, deletion, modification and query, list query result return type, one to many, many to one, many to many

Power application of 5g DTU wireless communication module

What are the advantages of VR panoramic production? Why is it favored?

Svg+js keyboard control path
随机推荐
美国众议院议员:数字美元将支持美元作为全球储备货币
Technology sharing | wvp+zlmediakit realizes streaming playback of camera gb28181
Ethernet ARP Protocol
Hello C (I) -- basics of C language
The third generation of power electronics semiconductors: SiC MOSFET learning notes (V) research on driving power supply
教程详解|在酷雷曼系统中如何编辑设置导览功能?
Scala IO writes data to a text file
Laravel framework knowledge
Enterprise level ~uni app network request encapsulation
How to use stm32subeide SWV function
【面试题】instancof和getClass()的区别
How does VR panorama make money? Based on the objective analysis of the market from two aspects
Tape SVG animation JS effect
Eye gaze estimation using webcam
Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it
时间统一系统
After 5 years of software testing in didi and ByteDance, it's too real
Using ADC to control brushless motor source program STM32 library function
Current situation analysis and development trend forecast report of global and Chinese acrylonitrile butadiene styrene industry from 2022 to 2028
5年,从“点点点”到现在的测试开发,我的成功值得每一个借鉴。