Question

On a winform, is there a way to draw a rectangle like this (without top) using the DrawRectangle method or a workaround?

Rectangle without top

Was it helpful?

Solution

You can try using the SetClip method:

private void DrawTopless(Graphics g, Rectangle r) {
  g.SetClip(new Rectangle(r.Left, r.Top, r.Width + 1, 10), CombineMode.Exclude);
  g.DrawRectangle(Pens.Red, r);
  g.ResetClip();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top