在Windows窗体C中使用圆角边框时无法最大化窗体#

问题描述 投票:0回答:1

我有一个带有圆形边框的表单,代码如下:

[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
    int nLeftRect,     // x-coordinate of upper-left corner
    int nTopRect,      // y-coordinate of upper-left corner
    int nRightRect,    // x-coordinate of lower-right corner
    int nBottomRect,   // y-coordinate of lower-right corner
    int nWidthEllipse, // height of ellipse
    int nHeightEllipse // width of ellipse
);

public Form1()
{
    InitializeComponent();
    Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 30, 30));
}

但问题是:当我最大化表单时,它没有正确最大化。它像这样最大化:Image请帮帮我...

c# windows-forms-designer
1个回答
0
投票

我找到答案......我应该清除我之前设置的所有边界:

private void btnMaximize_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Maximized)
            {
                this.WindowState = FormWindowState.Normal;
                btnMaximize.Image = Properties.Resources.maximize_Black;
                Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 30, 30));
            }
            else
            {
                this.WindowState = FormWindowState.Maximized;;
                btnMaximize.Image = Properties.Resources.maximize_Black_copy;
                Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 0, 0));
            }
        }

感谢所有想要帮助我的朋友。

© www.soinside.com 2019 - 2024. All rights reserved.