Shape Class

Some times we want to draw rounded rectangles or show a form or controls with rounded corners. The Shape class gives us that functionality. The class is very simple and 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.

Screen Shot

Code Example (VB.Net)

The Shape class in action:

Public Class Form1

    Private Sub RoundButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RoundButton.Click
        'Round the panel control corners.
        Me.Panel1.Region = Shape.RoundedRegion(Me.Panel1.Size, 10, Corners.None)
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        'Draw a rounded rectangle on this form (window).
        Dim rect As New Rectangle(20, 20, 300, 290)
        e.Graphics.DrawPath(Pens.Red, Shape.RoundedRectangle(rect, 8, Corners.None))
    End Sub

End Class


  • Project Name: Shape Class
  • Project Type: Class
  • Author: Arman Ghazanchyan

System Requirements

  • Visual Studio
  • Dot Net Framework


blog comments powered by Disqus