Published Date: 5/14/2010
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.
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)
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))
- Project Name: Shape Class
- Project Type: Class
- Author: Arman Ghazanchyan
- Visual Studio
- Dot Net Framework