c# - 为什么在切换 FormBorderStyle 属性后 WinForms 表单会移动(左 -7、-8)?
问题描述
我正在开发一个 WinForms 应用程序,它具有通过单击 F3 按钮隐藏和显示标题栏的功能。
一切正常,但我有多个显示器,当我切换标题栏的可见性(窗口最大化)时,我看到窗口向左移动了 -7、-8。
代码如下:
Form1.cs
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OnKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F3)
{
FormBorderStyle = FormBorderStyle == FormBorderStyle.None ?
FormBorderStyle.Sizable : FormBorderStyle.None;
}
}
}
}
Form1.Designer.cs
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
WindowState = FormWindowState.Maximized;
FormBorderStyle = FormBorderStyle.None;
this.KeyUp += OnKeyUp;
}
}
}
我尝试调试外部代码,发现 WinAPI 会返回这种转变。
显示器:戴尔 U2412M。比例:100%。分辨率:1920x1200。
解决方案
推荐阅读
- android - 如何将字符发送到打印命令并将它们打印在一行中?
- java - 如何在 blogger api 中按标签获取博客文章
- shell - 我想在将一些文档上传到其他 FTP 服务器时捕获 SFTP 错误
- html - 除了主元素 div 之外,如何在没有额外 div 的情况下停止 box-shadow 与悬停时的元素一起旋转?
- dart - 为什么sha256结果不同
- deep-learning - E-net 深度学习架构
- amp-html - 哪个规范链接是正确的
- makefile - android 使用 arm64-v8a ABI 编译错误“未定义的引用”
- soap - EWS 托管 api 检查用户帐户中是否存在事件
- scala - Guava Cache Generic LoadingCache