简体   繁体   English

如何调整无边框 MDI 表单的大小?

[英]How to resize a borderless MDI form?

I want this:我要这个:

Pretty much, my form is resizeable if BorderStyle is set to None and isMDIContainer = false;几乎,如果BorderStyle设置为None并且isMDIContainer = false; ,我的表单可以调整大小isMDIContainer = false;

But, how do I get my form resizeable if BordeStyle is set to None and isMDICOntainer = true ?但是,如果BordeStyle设置为None并且isMDICOntainer = true ,我如何使我的表单BordeStyle大小?

https://gyazo.com/6fe87f127a3b2768c152e64d372593c1 https://gyazo.com/6fe87f127a3b2768c152e64d372593c1

This is an example.这是一个例子。 You can see the form is resizeable just fine.您可以看到表单可以调整大小就好了。 But as soon as the MDI comes in play, it doesn't work anymore.但是一旦 MDI 发挥作用,它就不再起作用了。

Here is the current code:这是当前的代码:

private const int cCaption = 62;
private const int cGrip = 16;
protected override void OnPaint(PaintEventArgs e)
{
    Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
    ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
        
    rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
        
    // e.Graphics.FillRectangle(Brushes.Blue, rc);
}

protected override void WndProc(ref Message m)
{
    if (m.Msg == 0x84)
    {  // Trap WM_NCHITTEST
        Point pos = new Point(m.LParam.ToInt32());
        pos = this.PointToClient(pos);
        if (pos.Y < cCaption)
        {
            m.Result = (IntPtr)2;  // HTCAPTION
            return;
        }
        if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip)
        {
            m.Result = (IntPtr)17; // HTBOTTOMRIGHT
            return;
        }
    }
    base.WndProc(ref m);
}

The explanation from Jimi was right.吉米的解释是对的。 The OnPaint event only draws your Rectangle on the MainForm, while what you see is the MdiClient control. OnPaint事件仅在 MainForm 上绘制您的Rectangle ,而您看到的是MdiClient控件。 This control covers the background of the MainForm (like you set a panel control and set Dock = fill ), so you cannot see and click the rectangle at bottom right to resize.此控件覆盖 MainForm 的背景(就像您设置面板控件并设置Dock = fill ),因此您无法看到并单击右下角的矩形来调整大小。

One way for you to be able to see and click on the rectangle for resizing is set the padding for MainForm, like this:您能够查看并单击rectangle以调整大小的一种方法是为 MainForm 设置填充,如下所示:

        protected override void OnClientSizeChanged(EventArgs e)
        {
            if (this.WindowState != lastState || lastState == FormWindowState.Normal)
            {
                lastState = this.WindowState;
                OnWindowStateChange(e);
            }
            base.OnClientSizeChanged(e);
        }

        private void OnWindowStateChange(EventArgs e)
        {
            if (WindowState == FormWindowState.Maximized)
            {
                Padding = new Padding(0);
            }
            else
            {
                Padding = new Padding(7);
            }
        }

So at normal window state (not fullscreen), the MdiClient will not cover all surface of mainform.所以在正常的窗口状态(不是全屏), MdiClient不会覆盖主MdiClient所有表面。

在此处输入图片说明

I find the color of this is not good.我觉得这个颜色不太好。 So you may want to change the background of the main form that fit the background of MdiClient , or use this approach to draw rectangles around your form for resizing like normal.因此,您可能希望更改适合MdiClient背景的主窗体的背景,或者使用这种方法在窗体周围绘制rectangles以像正常一样调整大小。

How to resize borderless form from all edges 如何从所有边缘调整无边框形式的大小

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

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