WinForm - 使用单像素边框绘制调整大小的帧

时间:2008-09-18 15:52:01

标签: c# winforms resize border

在带有调整框架的Windows窗体中,框架边框以3-D凸起的外观绘制。我希望用我选择的颜色绘制平坦的单像素边框。

这是否可以在不必所有者的情况下绘制整个表格?

1 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

Point lastPoint = Point.Empty;
Panel leftResizer = new Panel();
leftResizer.Cursor = System.Windows.Forms.Cursors.SizeWE;
leftResizer.Dock = System.Windows.Forms.DockStyle.Left;
leftResizer.Size = new System.Drawing.Size(1, 100);
leftResizer.MouseDown += delegate(object sender, MouseEventArgs e) { 
  lastPoint = leftResizer.PointToScreen(e.Location); 
  leftResizer.Capture = true;
}
leftResizer.MouseMove += delegate(object sender, MouseEventArgs e) {
  if (lastPoint != Point.Empty) {
    Point newPoint = leftResizer.PointToScreen(e.Location);
    Location = new Point(Location.X + (newPoint.X - lastPoint.X), Location.Y);
    Width = Math.Max(MinimumSize.Width, Width - (newPoint.X - lastPoint.X));
    lastPoint = newPoint;
  }
}
leftResizer.MouseUp += delegate (object sender, MouseEventArgs e) { 
  lastPoint = Point.Empty;
  leftResizer.Capture = false;
}

form.BorderStyle = BorderStyle.None;
form.Add(leftResizer);