tmighty
tmighty

Reputation: 11399

VB.NET: Draw pen inside, not outside

I think I once read that a pen can be set up in such a way that it draws "inside" a path, and not outside. I don't want my path to be enlarged. To be specific, I would like to paint a border around my path, and the border should not go outside the path.

This unfortunately enlarges my path:

    Dim nPen As New Pen(Brushes.Black, 15)
    g.DrawPath(nPen, nPath)

If anybody understands what I want to do, I would be glad to get a reply! Thank you very much.

Upvotes: 1

Views: 397

Answers (1)

Styxxy
Styxxy

Reputation: 7517

You are looking for the Pen.Alignment property. It can have following values (source):

  • Center: Specifies that the Pen object is centered over the theoretical line.
  • Inset: Specifies that the Pen is positioned on the inside of the theoretical line.
  • Outset: Specifies the Pen is positioned on the outside of the theoretical line.
  • Left: Specifies the Pen is positioned to the left of the theoretical line.
  • Right: Specifies the Pen is positioned to the right of the theoretical line.

You'll need the Inset value.

Code example. You could use it like this:

Using nPen As New Pen(Brushes.Black, 15) With {.Alignment = Drawing2D.PenAlignment.Inset}
    g.DrawPath(nPen, nPath)
End Using

(Note that I am using using statement to ensure the object is being disposed.)

Upvotes: 1

Related Questions