Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:40:19+00:00 2026-05-23T14:40:19+00:00

Every sample code I’ve ever found for drawing rounded rectangles using GDI+ goes something

  • 0

Every sample code I’ve ever found for drawing rounded rectangles using GDI+ goes something like this (lifted and slightly modified from BobPowell.net):

  Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Panel1.Paint
    e.Graphics.Clear(SystemColors.Window)
    e.Graphics.SmoothingMode = SmoothingMode.None

    Call DrawRoundRect(e.Graphics, Pens.Red, 10, 10, 48, 24, 6)
  End Sub

  Public Sub DrawRoundRect(ByVal g As Graphics, ByVal p As Pen, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single, ByVal radius As Single)
    Using gp As New GraphicsPath()
      gp.StartFigure()
      gp.AddArc(x + width - radius, y, radius * 2, radius * 2, 270, 90)
      gp.AddArc(x + width - radius, y + height - radius, radius * 2, radius * 2, 0, 90)
      gp.AddArc(x, y + height - radius, radius * 2, radius * 2, 90, 90)
      gp.AddArc(x, y, radius * 2, radius * 2, 180, 90)
      gp.CloseFigure()
      g.DrawPath(p, gp)
    End Using
  End Sub

This produces a rounded rectangle where only the top left corner is accurate.

AntiAliasing has to be turned off because it is going through a remote desktop connection, and I can’t depend on it being available. Besides, I am looking for a crisp rounded rectangle.

enter image description here

I’ve tried resizing the other corners and changing the pen alignments, but nothing seems to produce a simple, accurate rounded rectangle.

Is there a way to draw a better rounded rectangle than this in good old winforms?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:40:20+00:00Added an answer on May 23, 2026 at 2:40 pm

    I have found the best solution to be just old-school Windows API:

    Private Sub DrawRoundRect(ByVal g As Graphics, ByVal r As Rectangle)
      Dim hDC As IntPtr = g.GetHdc
      Dim hPen As IntPtr = CreatePen(PS_SOLID, 0, ColorTranslator.ToWin32(Color.Red))
      Dim hOldPen As IntPtr = SelectObject(hDC, hPen)
      SelectObject(hDC, GetStockObject(NULL_BRUSH))
      RoundRect(hDC, r.Left, r.Top, r.Right - 1, r.Bottom - 1, 12, 12)
      SelectObject(hDC, hOldPen)
      DeleteObject(hPen)
      g.ReleaseHdc(hDC)
    End Sub
    

    This produces the symmetrical rounded rectangle I’ve been looking for:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading up on database cursors, and every bit of sample code I've
I am following sample code for sending an update notification every 10'seconds. The code
In this sample code the URL of the app seems to be determined by
Every sample that I have seen uses static XML in the xmldataprovider source, which
I'm new to development on the iPhone. Just about every sample project (as well
Every time I try to do something seemingly-simple in CSS, it doesn't work. I
Every method I write to encode a string in Java using 3DES can't be
Every sample I've seen uses stored procedures. I've adopted an old application written in
I have the following sample code where I download a pdf from the European
I have the following sample template code. {# @T('core.layout:Logged in as {0} {1}', @user('firstname'),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.