Results 1 to 4 of 4

Thread: Round the corners of rectangles and controls.

  1. #1
    PowerPoster VBDT's Avatar
    Join Date
    Sep 05
    Location
    CA - USA
    Posts
    2,919

    Round the corners of rectangles and controls.

    Class Shape. Last updated: 08/20/2008

    Description:
    Some times we want to draw rounded rectangles or show a form or controls with rounded corners. This class gives you that functionality. The class has two functions "RoundedRectangle" and "RoundedRegion". The "RoundedRectangle" rounds the corners of the rectangle and returns the graphics path. The "RoundedRegion" creates a rectangle-region, rounds the corners and returns the newly created region.
    Class shared methods:
    • RoundedRectangle – Returns the graphics path of the rounded-rectangle (parameters: rectangle, radius and four optional parameters for each corner).
    • RoundedRegion – Returns a newly created region with rounded corners (parameters: region size, radius and four optional parameters for each corner).
    Usage:
    VB Code:
    1. 'Draw a rounded rectangle in the form's paint event.
    2. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    3.     e.Graphics.DrawPath(Pens.Red, Shape.RoundedRectangle(New Rectangle(5, 5, 100, 100), 8, Shape.Corner.None))
    4. End Sub
    5.  
    6. 'Show the control on the form with rounded corners.
    7. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    8.     Me.Panel1.Region = Shape.RoundedRegion(Panel1.Size, 10, Shape.Corner.None)
    9. End Sub

    Please feel free to comment or notify me about any problems associated with the class.
    Attached Images Attached Images    
    Attached Files Attached Files

  2. #2
    New Member
    Join Date
    Apr 10
    Posts
    1

    Re: Round the corners of rectangles and controls.

    How could you make all the form corners (me.region) rounded? When I Try the Shape.Corner.BottomRight & so on, it only makes the first two rounded. When I call two instances, it gives me an error.

  3. #3
    PowerPoster VBDT's Avatar
    Join Date
    Sep 05
    Location
    CA - USA
    Posts
    2,919

    Re: Round the corners of rectangles and controls.

    Quote Originally Posted by Steve323 View Post
    How could you make all the form corners (me.region) rounded? When I Try the Shape.Corner.BottomRight & so on, it only makes the first two rounded. When I call two instances, it gives me an error.
    Me.Panel1.Region = Shape.RoundedRegion(Panel1.Size, 10, Shape.Corner.None)

  4. #4
    Junior Member
    Join Date
    Oct 11
    Posts
    19

    Re: Round the corners of rectangles and controls.

    A control with rounded corners should have set 'BorderStyle=None' ... !!

    Dietrich

Posting Permissions

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