Click here to Skip to main content
13,291,254 members (57,263 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 24 Nov 2011

How to create Rounded UserControl using Vb.Net

, 24 Nov 2011
Rate this:
Please Sign up or sign in to vote.
There are so many articals on "How to create Rounded UserControls" with C# Code.But very few codes
are written in Vb.Net. So i am publishing this Vb.Net code to design Rounded UserControl which helps you to Dsign your Rounded Control.

Use following Code :

Imports System.Drawing.Drawing2D
Public Class UserControl1
    Private _radius As Int32 = 20     'Radius of the Corner Curve
    Private _opacity As Int32 = 125   'Opacity of the Control
    Private _backColor As System.Drawing.Color = Color.Black 'Back Color of Control
    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim rect As Rectangle = Me.ClientRectangle 'Drawing Rounded Rectangle
        rect.X = rect.X + 1
        rect.Y = rect.Y + 1
        rect.Width -= 2
        rect.Height -= 2
        Using bb As GraphicsPath = GetPath(rect, _radius)
            Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                e.Graphics.FillPath(br, bb)
            End Using
        End Using
    End Sub
    'Returns the GraphicsPath to Draw a RoundedRectangle
    Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
        Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
        r = r << 1
        Dim path As GraphicsPath = New GraphicsPath()
        If r > 0 Then
            If (r > h) Then r = h
            If (r > w) Then r = w
            path.AddArc(x, y, r, r, 180, 90)
            path.AddArc(x + w - r, y, r, r, 270, 90)
            path.AddArc(x + w - r, y + h - r, r, r, 0, 90)
            path.AddArc(x, y + h - r, r, r, 90, 90)
        End If
        Return path
    End Function
End Class


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Manoj K Bhoir
Software Developer
India India
It always seems good to hear about me, but the thing I do is I code. I'm Interested in Designing Windows Based Application, Web Applications and building Mobile Applications. Currently restricting it to Android 4.0 applications, building Internet Based Applications using ASP.NET and contributing to bring the student community to a position which will help technology to reach the greatest heights ever. A very Big fan of Microsoft & Android..!!

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 3 How about the power of client side s... Pin
Eduard Lu30-Nov-11 19:16
memberEduard Lu30-Nov-11 19:16 
GeneralRe: The above source code doesn't appear to be web based. Pin
Ctznkane12-Dec-11 8:21
memberCtznkane12-Dec-11 8:21 
GeneralI completely disagree with SAKryukov.and for your kind infor... Pin
Manoj K Bhoir27-Nov-11 18:32
memberManoj K Bhoir27-Nov-11 18:32 
I completely disagree with SAKryukov.and for your kind information this is not a fake code.I only publish the code to rounded the sharp corners of the usercontrol and it works fine.If some one want to design rounded control then it is very usfull by altering and adding sum code and functionalities.
GeneralReason for my vote of 1 This is fake Rounded control, which ... Pin
SAKryukov26-Nov-11 14:12
mvpSAKryukov26-Nov-11 14:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 24 Nov 2011
Article Copyright 2011 by Manoj K Bhoir
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid