Results 1 to 4 of 4

Thread: Rounded Corners

  1. #1

    Thread Starter
    Addicted Member spyk3's Avatar
    Join Date
    Apr 2009
    Location
    Dothan, AL
    Posts
    218

    Rounded Corners

    First of all, I can't take full credit for this, as I borrowed this myself from somewhere, but can't remember where now.
    Anywho, I've noticed quite a many request in this and other forums to figure out how to round corners of an object.
    So i'm posting an Official Function that makes it very Easy.
    Simply Copy & Paste the following function into your form somewhere
    Round It Code:
    1. Private Sub makeRound(ByVal vObject As Object)
    2.         Dim p As New Drawing2D.GraphicsPath()
    3.         p.StartFigure()
    4.         p.AddArc(New Rectangle(0, 0, 20, 20), 180, 90)
    5.         p.AddLine(20, 0, vObject.Width - 20, 0)
    6.         p.AddArc(New Rectangle(vObject.Width - 20, 0, 20, 20), -90, 90)
    7.         p.AddLine(vObject.Width, 20, vObject.Width, vObject.Height - 20)
    8.         p.AddArc(New Rectangle(vObject.Width - 20, vObject.Height - 20, 20, 20), 0, 90)
    9.         p.AddLine(vObject.Width - 20, vObject.Height, 20, vObject.Height)
    10.         p.AddArc(New Rectangle(0, vObject.Height - 20, 20, 20), 90, 90)
    11.         p.CloseFigure()
    12.  
    13.         vObject.Region = New Region(p)
    14.     End Sub

    For more of a rounded curve try replacing all of the "20"s with "40"
    To make use on almost any object in a form simply:
    Use It Code:
    1. makeRound(yourObject)
    2. '    Like
    3. makeRound(TreeView1)

    Tada!

  2. #2
    Lively Member
    Join Date
    Sep 2010
    Location
    Canada
    Posts
    68

    Re: Rounded Corners

    Option Strict-compliant, safer, and more customizable version:
    Code:
        Private Sub MakeRound(ByVal c As Control, Optional ByVal radius As Integer = 20)
            Dim p As New Drawing2D.GraphicsPath()
            p.AddArc(New Rectangle(0, 0, radius, radius), 180, 90)
            p.AddLine(20, 0, vObject.Width - 20, 0)
            p.AddArc(New Rectangle(vObject.Width - radius, 0, radius, radius), -90, 90)
            p.AddLine(vObject.Width, 20, vObject.Width, vObject.Height - radius)
            p.AddArc(New Rectangle(vObject.Width - radius, vObject.Height - radius, radius, radius), 0, 90)
            p.AddLine(vObject.Width - 20, vObject.Height, 20, vObject.Height)
            p.AddArc(New Rectangle(0, vObject.Height - 20, 20, 20), 90, 90)
            p.CloseFigure()
    
            c.Region = New Region(p)
        End Sub
    P.S. radius should actually be diameter.

  3. #3

  4. #4

    Thread Starter
    Addicted Member spyk3's Avatar
    Join Date
    Apr 2009
    Location
    Dothan, AL
    Posts
    218

    Re: Rounded Corners

    Quote Originally Posted by boops boops View Post
    The lines with AddLine are unnecessary. Since it is all one figure, the path will extend from the end point of one arc to the next. BB
    Lol, I kinda figured as much, just figured I'd share the easy recipe I've been using with others questioning how to do it. I'll maybe break it down and explain it as well as perfect it later, right now, I'm extremely overworked and underpayed and have to get back to that, lol.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width