How can I draw a hollow rectangle using CreatePen?
- by LarsTech
Since using the DrawArc function in GDI+ isn't very accurate when drawing a small rounded rectangle, I am using RoundRect instead.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim hDC As IntPtr = e.Graphics.GetHdc
Dim rc As New Rectangle(10, 10, 64, 24)
Dim hPen As IntPtr = Win32.CreatePen(Win32.PenStyle.PS_SOLID, 0, _
ColorTranslator.ToWin32(Color.Green))
Dim hOldPen As IntPtr = Win32.SelectObject(hDC, hPen)
Call Win32.RoundRect(hDC, rc.Left, rc.Top, rc.Right, rc.Bottom, 10, 10)
Win32.SelectObject(hDC, hOldPen)
Win32.DeleteObject(hPen)
e.Graphics.ReleaseHdc(hDC)
MyBase.OnPaint(e)
End Sub
This will draw a nice rounded rectangle, but it will also fill it with a white brush, erasing what I don't want to have erased.
How can I draw this without erasing the inside of the rectangle?