Wordsmyth's Corner

How to Make Proper Borders Around Shapes

Explains how to get shapes with borders.

source article

Say I want a blue rectangle with a red border around it. One might assume I would simply call:

     Rectangle rectangle = new Rectangle(0, 0, 10, 10);
     graphics.DrawRectangle(Pens.Red, rectangle);
     graphics.FillRectangle(Brushes.Blue, rectangle);
But noooo - that would be too logical. The result is stupid - a rectangle with half a border.

Apparently the "fix" for this is to simply swap the order of the draw and fill:

       Rectangle rectangle = new Rectangle(0, 0, 10, 10);
       graphics.FillRectangle(Brushes.Blue, rectangle);
       graphics.DrawRectangle(Pens.Red, rectangle);