c# - How to lock a windows form in c# to be always be maximized?
问题描述
Im working on a windows form program and I want to make the main form always maximized ,I've tried setting the WindowState to Maximized and FormBorderStyle to FixedDialog/FixedSingle and it works but the maximize button is still there so I tried setting the MaximizeBox to false but then the form is full screen and it totally covers the taskbar which is the problem ,I don't want it to be over the taskbar. If anyone knows a solution or ever an alternative solution to the problem please feel free to help me out.
解决方案
保持FormBorderStyle = Sizable
。设置MaximizeBox = false
和MinimizeBox = false
。作为使用背后的代码
public partial class frmFixedMaximized : Form
{
private bool _changing;
public frmFixedMaximized()
{
InitializeComponent();
WindowState = FormWindowState.Maximized;
}
private void frmFixedMaximized_Shown(object sender, EventArgs e)
{
// Make resizing impossible.
MinimumSize = Size;
MaximumSize = Size;
}
private void frmFixedMaximized_LocationChanged(object sender, EventArgs e)
{
if (!_changing) {
_changing = true;
try {
// Restore maximized state.
WindowState = FormWindowState.Minimized;
WindowState = FormWindowState.Maximized;
} finally {
_changing = false;
}
}
}
}
这段代码的原因是用户仍然可以通过按住标题栏来拖动窗口。该_changing
变量防止LocationChanged
事件处理程序在无限循环中触发自身。
推荐阅读
- three.js - Autodesk forge 自定义几何图形
- axapta - 获取查找表的当前记录
- opencl - 如何在 Sycl+openCL+DPCPP 上定义和执行函数数组
- http - 是否可以在没有范围请求的情况下同时下载单个文件?
- performance - 如何对我的算法(在线俄罗斯方块)进行性能评估?
- angular - Angular Messenger 服务错误 TS2769:没有重载匹配此调用
- vba - VBA PowerPoint 表格单元格的格式
- c++ - 解析函数的问题(int 到 const char*)
- javascript - Chartjs Plugin Deferred 抛出“Uncaught TypeError: Cannot read property 'plugins' of undefined”错误
- java - 如何在 Java 的“游戏结束”屏幕上添加重启鼠标输入