C# - 无法设置 form.height
我在 C# 表单上的一对按钮单击事件处理程序中得到了以下代码:
class frmLogin
{
private const int SHORT_HEIGHT = 120;
private const int LONG_HEIGHT = 220;
private EventHandler ExpandHandler;
private EventHandler ShrinkHandler;
public frmLogin()
{
InitializeComponent();
ExpandHandler = new EventHandler(btnExpand_Click);
ShrinkHandler = new EventHandler(btnShrink_Click);
btnExpand.Click += ExpandHandler;
}
private void btnExpand_Click(object sender, EventArgs e)
{
this.Height = LONG_HEIGHT;
btnExpand.Text = "<< Hide Server";
btnExpand.Click -= ExpandHandler;
btnExpand.Click += ShrinkHandler;
}
private void btnShrink_Click(object sender, EventArgs e)
{
this.Height = SHORT_HEIGHT;
btnExpand.Text = "Choose Server >>";
btnExpand.Click -= ShrinkHandler;
btnExpand.Click += ExpandHandler;
}
}
文本更改发生时没有问题,但在一台特定的客户端计算机(Dell M4300 笔记本电脑工作站)上,高度更改不会生效。 有没有人解决过类似的问题,如果解决了,解决方法是什么?
I've got this code in a pair of button click event handlers on a C# form:
class frmLogin
{
private const int SHORT_HEIGHT = 120;
private const int LONG_HEIGHT = 220;
private EventHandler ExpandHandler;
private EventHandler ShrinkHandler;
public frmLogin()
{
InitializeComponent();
ExpandHandler = new EventHandler(btnExpand_Click);
ShrinkHandler = new EventHandler(btnShrink_Click);
btnExpand.Click += ExpandHandler;
}
private void btnExpand_Click(object sender, EventArgs e)
{
this.Height = LONG_HEIGHT;
btnExpand.Text = "<< Hide Server";
btnExpand.Click -= ExpandHandler;
btnExpand.Click += ShrinkHandler;
}
private void btnShrink_Click(object sender, EventArgs e)
{
this.Height = SHORT_HEIGHT;
btnExpand.Text = "Choose Server >>";
btnExpand.Click -= ShrinkHandler;
btnExpand.Click += ExpandHandler;
}
}
The text change occurs without issue, but on one particular client machine, a Dell M4300 laptop workstation, the height change does not take effect. Has anyone resolved a similar issue, and what was the fix if so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的猜测:该计算机上的 DPI 或系统字体大小不同,并且您的表单的 AutoScaleMode 是“Font”或“Dpi”,从而使表单的 MaximumSize 或 MaximumSize 阻止更改。
My guess: The DPI or system font size is different on that machine and your form's AutoScaleMode is either "Font" or "Dpi", making your form's MinimumSize or MaximumSize prevent the change.
检查笔记本电脑的显示模式,特别是检查宽高比设置。 有时,笔记本电脑会做一些奇怪的事情来适应宽而短的屏幕。
Check the display mode for the laptop, and in particular check the aspect-ratio setting. Sometimes laptops do weird things to facilitate the wide, short screen.
确保您没有将这些 AutoScale/Size/Whatever 属性之一设置为 true。
Make sure you do not have one of those AutoScale/Size/Whatever properties set to to true.