Click here to Skip to main content
11,639,861 members (66,298 online)
Click here to Skip to main content

Creating Windows Rounded Rectangular and Circular Forms

, 10 Jun 2011 CPOL 39.6K 4.6K 23
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Hassanoor
Software Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionCHANGING THE FORM LED TO GENERATION OF MANY OTHER FORMS Pin
KipkoechE11-Feb-15 6:35
memberKipkoechE11-Feb-15 6:35 
QuestionCLOSING A ROUND FORM Pin
KipkoechE11-Feb-15 6:33
memberKipkoechE11-Feb-15 6:33 
QuestionHelpful Pin
Zenu Khas30-Jun-14 6:29
memberZenu Khas30-Jun-14 6:29 
QuestionNot useful Pin
glenda patricia sevilla27-Aug-13 20:45
memberglenda patricia sevilla27-Aug-13 20:45 
QuestionA possible useful feature Pin
bartj6313-Aug-12 19:21
memberbartj6313-Aug-12 19:21 
GeneralMy vote of 2 Pin
GeekForChrist9-Jul-12 3:03
memberGeekForChrist9-Jul-12 3:03 
QuestionHow to get Rounded Rectangular form without listbox, just as default shape for all project forms? Pin
Member 800456027-Jul-11 22:16
memberMember 800456027-Jul-11 22:16 
AnswerRe: How to get Rounded Rectangular form without listbox, just as default shape for all project forms? Pin
hassanoor4-Aug-11 21:49
memberhassanoor4-Aug-11 21:49 
GeneralNot WebForms Pin
AspDotNetDev10-Jun-11 9:51
mvpAspDotNetDev10-Jun-11 9:51 
GeneralNot very informative... Pin
Naerling10-Jun-11 9:49
memberNaerling10-Jun-11 9:49 
GeneralRe: Not very informative... Pin
AspDotNetDev10-Jun-11 10:03
mvpAspDotNetDev10-Jun-11 10:03 
GeneralRe: Not very informative... Pin
Naerling10-Jun-11 10:18
memberNaerling10-Jun-11 10:18 
GeneralMy vote of 2 Pin
Skif10-Jun-11 7:01
memberSkif10-Jun-11 7:01 
GeneralYou should rename the title Pin
After205023-May-11 1:58
memberAfter205023-May-11 1:58 
Generalnice Pin
CIDev18-May-11 5:24
memberCIDev18-May-11 5:24 
GeneralAdding custom skins for Forms in VB.Net Pin
EscKey200418-May-11 3:56
memberEscKey200418-May-11 3:56 
GeneralRe: Adding custom skins for Forms in VB.Net Pin
EdMan19610-Jun-11 10:53
memberEdMan19610-Jun-11 10:53 

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.

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