C# - 无法设置 form.height

发布于 2024-07-09 12:29:49 字数 1060 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暗地喜欢 2024-07-16 12:29:49

我的猜测:该计算机上的 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.

情话难免假 2024-07-16 12:29:49

检查笔记本电脑的显示模式,特别是检查宽高比设置。 有时,笔记本电脑会做一些奇怪的事情来适应宽而短的屏幕。

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.

歌入人心 2024-07-16 12:29:49

确保您没有将这些 AutoScale/Size/Whatever 属性之一设置为 true。

Make sure you do not have one of those AutoScale/Size/Whatever properties set to to true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文