Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to draw rounded rectangle?

How to draw rounded rectangle?

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    god4k
    wrote on last edited by
    #1

    Hi Sir and Madam, How to draw rounded rectangle? Thank You.

    C M 2 Replies Last reply
    0
    • G god4k

      Hi Sir and Madam, How to draw rounded rectangle? Thank You.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I seem to recall writing an article on how to do it, did you try searching the site ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • G god4k

        Hi Sir and Madam, How to draw rounded rectangle? Thank You.

        M Offline
        M Offline
        Mandaar Kulkarni
        wrote on last edited by
        #3

        Try Following. Good Luck. float radius = 5; // Radius for round curve float diameter = 2 * radius; // Basic dimensions where Roundrect is to be drawn Rectangle BaseRect = new Rectangle(x1, y1, x2, y2); SizeF RoundSize = new SizeF(diameter, diameter); RectangleF RoundArc = new RectangleF(BaseRect.Location, RoundSize); // Graphics object Graphics G = Graphics.FromHwnd(this.Handle); // Create Graphics path GraphicsPath Gp = new GraphicsPath(); Pen P = new Pen(Brushes.Black); // Top left arc RoundArc.X = BaseRect.Left; RoundArc.Y = BaseRect.Top; Gp.AddArc(RoundArc, 180, 90); //Top right arc RoundArc.X = (BaseRect.Right - diameter); RoundArc.Y = BaseRect.Top; Gp.AddArc(RoundArc, 270, 90); // Bottom right arc RoundArc.X = (BaseRect.Right - diameter); RoundArc.Y = BaseRect.Bottom - diameter; Gp.AddArc(RoundArc, 0, 90); // Bottom left arc RoundArc.X = BaseRect.Left; RoundArc.Y = (BaseRect.Bottom - diameter); Gp.AddArc(RoundArc, 90, 90); // Close Graphics path Gp.CloseFigure(); // Draw graphics path G.DrawPath(P, Gp);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups