码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C# Winform 最大化遮挡任务栏和全屏显示问题


    在打开最大化窗体时,如果不进行配置,那么默认情况下窗体是被任务栏档住,导致有部分界面看不见,看看下面代码的效果,也许对你有帮助

    新建一个Winform项目,添加三个按钮,给三个按钮添加点击事件

    代码:

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Threading.Tasks;
    9. using System.Windows.Forms;
    10. namespace Test5
    11. {
    12. public partial class Form1 : Form
    13. {
    14. public Form1()
    15. {
    16. InitializeComponent();
    17. }
    18. private Size WindowMaximumSize;
    19. private void Form1_Load(object sender, EventArgs e)
    20. {
    21. WindowMaximumSize = this.MaximumSize;
    22. this.TopMost = true;
    23. }
    24. private void button1_Click(object sender, EventArgs e)
    25. {
    26. //任务栏不会被遮挡
    27. if (this.WindowState == FormWindowState.Maximized)
    28. {
    29. this.WindowState = FormWindowState.Normal;
    30. }
    31. else
    32. {
    33. this.WindowState = FormWindowState.Maximized;
    34. }
    35. }
    36. private void button2_Click(object sender, EventArgs e)
    37. {
    38. //任务栏会被遮挡
    39. if (this.WindowState == FormWindowState.Maximized)
    40. {
    41. this.FormBorderStyle = FormBorderStyle.FixedSingle;
    42. this.WindowState = FormWindowState.Normal;
    43. }
    44. else
    45. {
    46. this.FormBorderStyle = FormBorderStyle.None;
    47. this.MaximumSize = WindowMaximumSize;
    48. this.WindowState = FormWindowState.Maximized;
    49. }
    50. }
    51. private void button3_Click(object sender, EventArgs e)
    52. {
    53. //任务栏不会被遮挡
    54. if (this.WindowState == FormWindowState.Maximized)
    55. {
    56. this.FormBorderStyle = FormBorderStyle.FixedSingle;
    57. this.WindowState = FormWindowState.Normal;
    58. }
    59. else
    60. {
    61. this.FormBorderStyle = FormBorderStyle.FixedSingle;
    62. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
    63. this.WindowState = FormWindowState.Maximized;
    64. }
    65. }
    66. }
    67. }

    效果:

    点击按钮1,会最大化,但窗体不会遮挡任务栏,

    点击按钮2,会全屏显示,

    点击按钮3,会最大化,但窗体不会遮挡任务栏,

    end

  • 相关阅读:
    基于个性化推荐的图书网站设计与实现
    springboot多模块扫包中的@SpringBootApplication、@ComponentScan和@MapperScan问题
    C++核心编程:P19->STL----常用算法(下)
    python基础语法-HTML基础(简单实用)
    好看的水滴登录页面
    我的世界Minecraft基岩版开服教程(Linux)开服器开服包下载开服网站服务器开服核心开服端开服软件mac版Java启动器
    HTML+CSS之如何找BUG
    5分钟搞懂MySQL - 行转列
    一同走进Linux的“基操”世界
    未能将“obj\Debug\IOControl.exe”复制到“bin\Debug\IOControl.exe
  • 原文地址:https://blog.csdn.net/qq_38693757/article/details/125445723
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号