Click here to Skip to main content
Licence CPOL
First Posted 18 May 2011
Views 15,185
Downloads 1,752
Bookmarked 13 times

Creating Windows Rounded Rectangular and Circular Forms

By | 10 Jun 2011 | Article
Designing forms with rounded corners using Visual Studio 2010
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

Follow on Twitter Follow on Twitter


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
QuestionHow to get Rounded Rectangular form without listbox, just as default shape for all project forms? PinmemberMember 800456022:16 27 Jul '11  
AnswerRe: How to get Rounded Rectangular form without listbox, just as default shape for all project forms? Pinmemberhassanoor21:49 4 Aug '11  
GeneralNot WebForms PinmvpAspDotNetDev9:51 10 Jun '11  
GeneralNot very informative... PinmemberNaerling9:49 10 Jun '11  
GeneralRe: Not very informative... PinmvpAspDotNetDev10:03 10 Jun '11  
GeneralRe: Not very informative... PinmemberNaerling10:18 10 Jun '11  
GeneralMy vote of 2 PinmemberSkif7:01 10 Jun '11  
GeneralYou should rename the title PinmemberAfter20501:58 23 May '11  
Generalnice PinmemberCIDev5:24 18 May '11  
GeneralAdding custom skins for Forms in VB.Net PinmemberEscKey20043:56 18 May '11  
GeneralRe: Adding custom skins for Forms in VB.Net PinmemberEdMan19610:53 10 Jun '11  

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 10 Jun 2011
Article Copyright 2011 by hassanoor
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid