WinForm - رسم إطار لتغيير الحجم باستخدام حدود أحادية البكسل

StackOverflow https://stackoverflow.com/questions/93811

  •  01-07-2019
  •  | 
  •  

سؤال

في نموذج Windows المزود بإطار لتغيير الحجم، يتم رسم حدود الإطار بمظهر ثلاثي الأبعاد مرتفع.أرغب في الرسم بحد بكسل واحد مسطح بلون من اختياري.

هل هذا ممكن دون الحاجة إلى رسم المالك للنموذج بأكمله؟

هل كانت مفيدة؟

المحلول

يمكنك تجربة شيء مثل هذا:

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top