调整Windows窗体的大小

本文关键字:窗体 Windows 调整 | 更新日期: 2023-09-27 17:51:16

我有一个窗体,它的FormBorderStyle设置为可缩放。这就形成了右下方的握把。调整窗口大小的唯一方法是将鼠标精确地放在窗口边缘。我想知道是否有一种方法来改变光标,以便能够调整大小,当用户鼠标在手柄上,或者如果我可以增加范围,它将允许你在边缘上调整大小,这样你就不必如此精确与你的鼠标位置。

调整Windows窗体的大小

这里有一个类似的SO问题的链接。这个向量是没有边界的,所以你可能要用不同的方法,但是应该给你一个方向。我将在这里重新粘贴他的代码以完成:

  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
      this.FormBorderStyle = FormBorderStyle.None;
      this.DoubleBuffered = true;
      this.SetStyle(ControlStyles.ResizeRedraw, true);
    }
    private const int cGrip = 16;      // Grip size
    private const int cCaption = 32;   // Caption bar height;
    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.DarkBlue, rc);
    }
    protected override void WndProc(ref Message m) {
      if (m.Msg == 0x84) {  // Trap WM_NCHITTEST
        Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
        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);
    }
  }

try this

yourObject.Cursor = Cursors.SizeAll;

本网站上的更多信息:MSDN