In .NET WinForms, How to Make a Borderless Form with a Height less than 34?

后端 未结 1 1796
终归单人心
终归单人心 2021-01-26 17:59

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

I took the Form that was created with the project, and set the .FormBo

相关标签:
1条回答
  • 2021-01-26 18:35

    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".

    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
            );
        }
    

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

    0 讨论(0)
提交回复
热议问题