Click here to Skip to main content
Licence 
First Posted 29 Apr 2004
Views 75,878
Bookmarked 15 times

Drawing Round-Edged Rectangle Using VB.NET

By | 29 Apr 2004 | Article
This code can be used to draw Round Edged Rectangles using VB.NET

Sample Image - ImageRoundEdgeRectangle.gif

Introduction

This is a Article explains about drawing a Round-edge Rectangle using VB.Net. It will help beginners to learn 'How to make use of GDI+ in VB.NET

The input parameters are Xaxis, Yaxis, Width, Height and Diameter. Based on the diameter, the calculations are made. For an example I have put the color of the rectangle as Black.
If user want to change they can chage the color.

Hope it will be helpful.

Public Sub DrawRoundedRectangle(ByVal objGraphics As Graphics, _
                                ByVal m_intxAxis As Integer, _
                                ByVal m_intyAxis As Integer, _
                                ByVal m_intWidth As Integer, _
                                ByVal m_intHeight As Integer, _
                                ByVal m_diameter As Integer)

 
   
   'Dim g As Graphics
    Dim BaseRect As New RectangleF(m_intxAxis, m_intyAxis, m_intWidth, 
                                  m_intHeight)
    Dim ArcRect As New RectangleF(BaseRect.Location,
                              New SizeF(m_diameter, m_diameter))
    'top left Arc
    objGraphics.DrawArc(Pens.Black, ArcRect, 180, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + CInt(m_diameter / 2), 
                         m_intyAxis, 
                         m_intxAxis + m_intWidth - CInt(m_diameter / 2), 
                         m_intyAxis)

    ' top right arc
    ArcRect.X = BaseRect.Right - m_diameter
    objGraphics.DrawArc(Pens.Black, ArcRect, 270, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + m_intWidth, 
                         m_intyAxis + CInt(m_diameter / 2), 
                         m_intxAxis + m_intWidth, 
                         m_intyAxis + m_intHeight - CInt(m_diameter / 2))

    ' bottom right arc
    ArcRect.Y = BaseRect.Bottom - m_diameter
    objGraphics.DrawArc(Pens.Black, ArcRect, 0, 90)
    objGraphics.DrawLine(Pens.Black, m_intxAxis + CInt(m_diameter / 2), 
                         m_intyAxis + m_intHeight, 
                         m_intxAxis + m_intWidth - CInt(m_diameter / 2), 
                         m_intyAxis + m_intHeight)

    ' bottom left arc
    ArcRect.X = BaseRect.Left
    objGraphics.DrawArc(Pens.Black, ArcRect, 90, 90)
    objGraphics.DrawLine(Pens.Black, 
                         m_intxAxis, m_intyAxis + CInt(m_diameter / 2), 
                         m_intxAxis, 
                         m_intyAxis + m_intHeight - CInt(m_diameter / 2))

End Sub

You can call this method from anywhere by just giving the required values to the input parameters.You can chnage the input parameters like

Private Sub DrawRoundedRectangle(ByVal rectf as RectangleF, _<BR>                                 ByVal m_diameter As Integer)
and from RectangleF object You can get the values of xAxis, yAxis, width and Height of the rectangles.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Karthikeyan Muthurajan

Web Developer

India India

Member

Working as a S/W Engineer with 3+ years of experience
Having MCAD in .NET
Selected as Microsoft India Community Star

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembersarthakganguly21:50 21 Jul '11  
General[Message Deleted] PinmemberTriston J. Taylor8:30 21 Nov '08  
GeneralI Modified this code better [modified] PinmemberTriston J. Taylor9:03 21 Nov '08  
GeneralRe: I Modified this code better PinmemberTriston J. Taylor9:10 21 Nov '08  
GeneralRe: I Modified this code better PinmemberKarthikeyan Muthurajan17:36 23 Nov '08  
GeneralRe: I Modified this code better Uh Oh! PinmemberTriston J. Taylor9:59 21 Nov '08  
GeneralThanks, Sort of PinmemberSteve Clarke15:54 31 Jul '04  
QuestionWhat use is this? Pinmembermav.northwind3:17 30 Apr '04  
AnswerRe: What use is this? PinsitebuilderUwe Keim8:00 30 Apr '04  
GeneralRe: What use is this? PinmemberKarthikeyan Muthurajan18:57 2 May '04  
GeneralRe: What use is this? PinmemberLove.net19:49 3 May '04  
GeneralRe: What use is this? PinmemberDDnDD11:14 3 Feb '05  
GeneralRe: What use is this? PinmemberDDnDD12:01 3 Feb '05  
GeneralRe: What use is this? PinmemberGraemeg330:54 18 Jan '07  
GeneralRe: What use is this? Pinmemberphil_the23:34 16 Aug '07  
AnswerRe: What use is this? PinmemberTriston J. Taylor16:23 21 Nov '08  
GeneralRe: What use is this? PinmemberJBenhart21:33 13 Nov '11  
GeneralRe: What use is this? PinsussAnonymous13:22 24 Feb '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 30 Apr 2004
Article Copyright 2004 by Karthikeyan Muthurajan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid