Click here to Skip to main content
Click here to Skip to main content

Creating Windows Rounded Rectangular and Circular Forms

By , 10 Jun 2011
 
Sample Image - maximum width is 600 pixels

Sample Image - maximum width is 600 pixels

Introduction

This article guides you how to create forms with rounded corners. This article is helpful for those who wanted to create forms with rounded corners, in contrast to those regular forms, but are stuck and can’t understand how to do it? Now, there is no need to panic. This project will show you how to make a program that creates forms with rounded corners. Make your forms different from others and change the look of your application in a way that appeals to the user.

Using the Code

Main Coding

First start a new project, select window form application and save it as "sampleprogram". You will see a form is created named as "Form1.vb", Rename it as "frmmain" in the Solution Explorer (if you have not found the solution explorer, then select it from Menu "View->Solution Explorer". Alternatively, you can use shortcut keys, i.e. ctrl+alt+L). Double click frmmain.vb to see the design view. Now, before going further, set the following properties of the form 'frmmain':

  • MaximizeBox: False
  • MinimizeBox: False
  • StartPosition: CenterScreen
  • Size: 500,500
  • FormBorderStyle: None

Now, click on the "View Code" and write the following code in the frmmain's paint method.
i.e. Write the Subroutine "frmmain_Paint".

Public Class frmmain

    Private Sub frmmain_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim gp As New System.Drawing.Drawing2D.GraphicsPath
        If cirOrec = 0 Then 'If Rounded Rectangle is selected

            If intval = 0 Then 
                intval = 200
            End If

        Dim chgcorn As Integer = intval  'Change the value and get the 
        'desired Rounded corner, 
        'keep in mind that the value should be divisible by 10.

        ' check whether the entered number is divisible by 10 or not, 
        ' if not then make it.
        If chgcorn Mod 10 <> 0 Then
            chgcorn = chgcorn - (chgcorn Mod 10)
        End If

        Dim r1 As New Rectangle(0, Me.Height - chgcorn, chgcorn, chgcorn)
        Dim r2 As New Rectangle(Me.Width - chgcorn + 1, _
			Me.Height - chgcorn, chgcorn, chgcorn)

        'creating the upper Arc
        gp.AddArc(0, 0, chgcorn, chgcorn, 180, 90)
        gp.AddArc(Me.Width - chgcorn + 1, 0, chgcorn, chgcorn, 270, 90)

        'Creating the Body
        gp.AddRectangle(New Rectangle(0, chgcorn / 2, Me.Width, Me.Height - chgcorn))

        'Creating the lower Arc
        gp.AddArc(r1, -270, 90)
        gp.AddArc(r2, 360, 90)

        Me.BackColor = Color.Black
	   Else              'If Circular form type is selected
            If intval = 0 Then
                intval = Me.Width
            End If
            If intval2 = 0 Then
                intval2 = Me.Height
            End If
            gp.AddEllipse(New Rectangle(0, 0, intval, intval2))
            Me.BackColor = Color.IndianRed
        End If
        Region = New Region(gp)
    End Sub

   'Now code for closing the Form1 

   Private Sub frmmain_Click(ByVal sender As System.Object, _
		ByVal e As System.EventArgs) Handles Button1.Click
	Me.close()
    End Sub
End Class
...

NOTE: Select the Form type you want to create from the combobox. For Rounded rectangular form, enter the arc value, and hit create button.

Sample Image - maximum width is 600 pixels

For Circular form, enter the height and width, and hit create button.

Sample Image - maximum width is 600 pixels

But, the value should be less than 400 because I've set the form-size 500 X 500.
For the complete code, download the source code.

Motive

The motive of posting this article is to help those who want to create rounded forms, but they didn't get any help. I searched on the internet and didn't get any desired results (many websites have shown Rounded corners only at the upper part of the Form, i.e., only upper-left and upper-right corners. But, what about the lower part of the Form?). This project shows all the four corners of the Form rounded.

History

  • 18th May, 2011: Initial post
  • 19th May, 2011: Article updated - With these changes, you just have to change the value of chgcorn and all the four corners will be rounded accordingly.
  • 10th June, 2011: Article updated

License

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

About the Author

Hassanoor
Software Developer
India India
Member
No Biography provided

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionA possible useful featurememberbartj6313 Aug '12 - 19:21 
GeneralMy vote of 2memberGeekForChrist9 Jul '12 - 3:03 
QuestionHow to get Rounded Rectangular form without listbox, just as default shape for all project forms?memberMember 800456027 Jul '11 - 22:16 
AnswerRe: How to get Rounded Rectangular form without listbox, just as default shape for all project forms?memberhassanoor4 Aug '11 - 21:49 
GeneralNot WebFormsmvpAspDotNetDev10 Jun '11 - 9:51 
GeneralNot very informative...memberNaerling10 Jun '11 - 9:49 
GeneralRe: Not very informative...mvpAspDotNetDev10 Jun '11 - 10:03 
GeneralRe: Not very informative...memberNaerling10 Jun '11 - 10:18 
GeneralMy vote of 2memberSkif10 Jun '11 - 7:01 
GeneralYou should rename the titlememberAfter205023 May '11 - 1:58 
GeneralnicememberCIDev18 May '11 - 5:24 
GeneralAdding custom skins for Forms in VB.NetmemberEscKey200418 May '11 - 3:56 
GeneralRe: Adding custom skins for Forms in VB.NetmemberEdMan19610 Jun '11 - 10:53 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 10 Jun 2011
Article Copyright 2011 by Hassanoor
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid