如何使用CreatePen绘制空心矩形?

| 由于在绘制小圆角矩形时,在GDI +中使用DrawArc函数不是很准确,因此我改用RoundRect。
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
这将绘制一个不错的圆角矩形,但也会用白色笔刷填充该矩形,以擦除我不想删除的内容。 如何在不删除矩形内部的情况下绘制此图形?     
已邀请:
        在绘制矩形之前,您只需要选择普通空心笔刷即可。使用HOLLOW_BRUSH调用GetStockObject,然后以与选择笔相同的方式将其选择到设备上下文中。     
        我使用这样的方法。对我来说很好。
private static GraphicsPath CreateRoundRectranglePath(Rectangle rect, Size rounding)
{
    var path = new GraphicsPath();
    var l = rect.Left;
    var t = rect.Top;
    var w = rect.Width;
    var h = rect.Height;
    var rx = rounding.Width;
    var dx = rounding.Width << 1;
    var ry = rounding.Height;
    var dy = rounding.Height << 1;
    path.AddArc(l, t, dx, dy, 180, 90); // topleft
    path.AddLine(l + rx, t, l + w - rx, t); // top
    path.AddArc(l + w - dx, t, dx, dy, 270, 90); // topright
    path.AddLine(l + w, t + ry, l + w, t + h - ry); // right
    path.AddArc(l + w - dx, t + h - dy, dx, dy, 0, 90); // bottomright
    path.AddLine(l + w - rx, t + h, l + rx, t + h); // bottom
    path.AddArc(l, t + h - dy, dx, dy, 90, 90); // bottomleft
    path.AddLine(l, t + h - ry, l, t + ry); // left
    path.CloseFigure();
    return path;
}
    

要回复问题请先登录注册