0

我想做无边界的形式。我的问题是,当我想要调整表单大小(在左侧或顶部)时,另一侧的表单正在跳跃。(见附件 gif。)我尝试了 SetWindowPos 和 WndProc 但类似的问题。

问题:如何使用 ResizeRedraw 和 Doublebuffering 调整无边框表单的大小而不会出现故障?

这是我的简化代码:

Public Class Form1
  Public Sub New()
      DoubleBuffered = True
      SetStyle(ControlStyles.ResizeRedraw, True)
      FormBorderStyle = FormBorderStyle.None
  End Sub
  Dim down As Boolean = False
  Dim _Right As Integer = 0
  Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
      _Right = Right
      down = True
  End Sub
  Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
      If down Then
          Dim xy As Point = PointToScreen(e.Location)
          SetBounds(xy.X - 2, Me.Top, _Right - xy.X - 2, Height)
      End If
  End Sub
End Class

故障动画 GIF

操作系统:Windows 7

开发:VS 2015、VB、.NET 2.0

4

1 回答 1

0

试试这个,它是一些基于 wndproc 的 C# 代码。

protected override void WndProc(ref Message m)

    {
        const int RESIZE_HANDLE_SIZE = 10;

        switch (m.Msg)
        {
            case 0x0084/*NCHITTEST*/ :
                base.WndProc(ref m);

                if ((int)m.Result == 0x01/*HTCLIENT*/)
                {
                    Point screenPoint = new Point(m.LParam.ToInt32());
                    Point clientPoint = this.PointToClient(screenPoint);
                    if (clientPoint.Y <= RESIZE_HANDLE_SIZE)
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)13/*HTTOPLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)12/*HTTOP*/ ;
                        else
                            m.Result = (IntPtr)14/*HTTOPRIGHT*/ ;
                    }
                    else if (clientPoint.Y <= (Size.Height - RESIZE_HANDLE_SIZE))
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)10/*HTLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)2/*HTCAPTION*/ ;
                        else
                            m.Result = (IntPtr)11/*HTRIGHT*/ ;
                    }
                    else
                    {
                        if (clientPoint.X <= RESIZE_HANDLE_SIZE)
                            m.Result = (IntPtr)16/*HTBOTTOMLEFT*/ ;
                        else if (clientPoint.X < (Size.Width - RESIZE_HANDLE_SIZE))
                            m.Result = (IntPtr)15/*HTBOTTOM*/ ;
                        else
                            m.Result = (IntPtr)17/*HTBOTTOMRIGHT*/ ;
                    }
                }
                return;
        }
        base.WndProc(ref m);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.Style |= 0x20000; // <--- use 0x20000
            return cp;
        }
    }
于 2020-12-20T18:29:26.757 回答