繁体   English   中英

自定义表格的边框大小

[英]Custom Form Resizing by Border

我有一个没有边框和标题栏的自定义窗体。 我使用panel(width = 1px)模拟边框。 除左边框和上边框外,其他所有功能都很好。 当我尝试减小表单的大小时(通过将其拖动到右侧),当表单的大小== this.MinimumSize时,它可以正常工作。 它开始向右移动。 我只想更改大小,不要移动...这是我的leftBorder代码。 我如何修改它以仅更改大小?

    private void borderW_MouseDown(object sender, MouseEventArgs e)
    {
        Active = true;

    }


    private void borderW_MouseMove(object sender, MouseEventArgs e)
    {
        if (Active)
        {
            if (e.X < 0)
            {
                this.Location = new Point(this.Left + e.X, this.Top);
                this.Size = new Size(this.Width - e.X, this.Height);
            }
            else
            {
                this.Size = new Size(this.Width - e.X, this.Height);
                this.Location = new Point(this.Left + e.X, this.Top);
            }
        }
    }

    private void borderW_MouseUp(object sender, MouseEventArgs e)
    {
        Active = false;
    }

将此函数粘贴到您的表单中。 它是一个替代,阻止移动表格。

但是,您必须使其符合条件,使其仅在表单的左侧与form.left + form.width(根据我对您的问题的理解)相同时才处于活动状态。

protected override void WndProc( ref Message m )
{
const int WM_NCLBUTTONDOWN = 161;
const int WM_SYSCOMMAND = 274;
const int HTCAPTION = 2;
const int SC_MOVE = 61456;
if ( (m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() == SC_MOVE) )
return;
if ( (m.Msg == WM_NCLBUTTONDOWN) && (m.WParam.ToInt32() == HTCAPTION)
)
return;
base.WndProc( ref m );
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM