1

I attempt to draw lines on specific coordinates using a Graphics.AddRectangle() and Graphics.DrawPath().

The parameters of my Rectangle:

Dim objPath As New GraphicsPath
objPath.AddRectangle(New Rectangle(0, 0, Me.Width, 1))

Then I draw it using DrawPath:

objPen.Width = 1
objGraphics.DrawPath(objPen, objPath)

I expect a "line" (rectangle) on the top of my graphic having a width of exactly 1px. Result: It draws a line of 2px width.

Demonstration of the 2px width drawing

Demonstration of the 2px width drawing

What is the cause of this behaviour?

djv
  • 15,168
  • 7
  • 48
  • 72
  • Why are you drawing a rectangle instead of a line? -- Check the `Pen.Alignment` property -- The notes about the Pen here: [Graphics DrawPath produces unexpected results when rendering text](https://stackoverflow.com/a/68877110/7444103) may be useful – Jimi Jul 13 '23 at 14:48
  • @Jimi I was looking for an alternative to `Graphics.AddLine`. It turned out that the use of Pen is the reason for this behavior - I will answer this question myself soon – Bender110001 Jul 14 '23 at 12:49

0 Answers0