在.NET WinForms中,如何制作高度小于34的无边界表单? [英] In .NET WinForms, How to Make a Borderless Form with a Height less than 34?

查看:41
本文介绍了在.NET WinForms中,如何制作高度小于34的无边界表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio,并使用C#创建了一个新的Windows应用程序,该应用程序使用WinForms.

I am using Visual Studio, and created a new Windows Application in C#, that uses WinForms.

我采用了随项目创建的Form,并将 .FormBorderStyle 属性设置为 None .

I took the Form that was created with the project, and set the .FormBorderStyle property to None.

然后我将表格的高度设置为18.

I then set the height of the Form to 18.

在设计器上,一切都很好,它的确显示为height = 18.

On the designer everything is well, it does appear as height=18.

但是当我运行它时,高度会增加,并且由于某种原因会变为34.

But when I run it, the height grows, and changes to 34 for some reason.

我需要表格高度为18,而不是34 ..

I need the form height to be 18, not 34..

我该怎么做才能使其达到我想要的高度?

What can I do to get it to the Height that I want?

谢谢

推荐答案

Winforms将最小尺寸限制应用于基于使标题栏保持可用状态的表单.即使表单没有表单,大多数程序员也将其称为错误".

Winforms applies an minimum size constraint to a form that's based on keeping the caption bar usable. Even if the form doesn't have one, a quirk that most programmers call "bug".

但是,您仍然可以通过在Load事件的事件处理程序中设置ClientSize属性来覆盖最终大小.请当心需要在具有不同视频DPI设置的计算机上重新缩放窗口,您要对尺寸进行硬编码.最好的方法是根据控件的位置调整它的大小.例如:

You can however still override the final size by setting the ClientSize property in an event handler for the Load event. Do beware the need to rescale the window on a machine with a different video DPI setting, you do not want to hard-code the size. Best way is to resize it based on the position of a control. For example:

    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);
        this.ClientSize = new Size(
            this.ClientSize.Width,
            OKButton.Bottom + OKButton.Margin.Bottom
        );
    }

假设名为OKButton的控件是最底层的控件.进行必要的调整.

With the assumption that a control named OKButton is the bottom one. Tweak as necessary.

这篇关于在.NET WinForms中,如何制作高度小于34的无边界表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆