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
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 '
Now, click on the "View Code" and write the following code in the
i.e. Write the Subroutine "
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 intval = 0 Then
intval = 200
Dim chgcorn As Integer = intval
If chgcorn Mod 10 <> 0 Then
chgcorn = chgcorn - (chgcorn Mod 10)
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)
gp.AddArc(0, 0, chgcorn, chgcorn, 180, 90)
gp.AddArc(Me.Width - chgcorn + 1, 0, chgcorn, chgcorn, 270, 90)
gp.AddRectangle(New Rectangle(0, chgcorn / 2, Me.Width, Me.Height - chgcorn))
gp.AddArc(r1, -270, 90)
gp.AddArc(r2, 360, 90)
Me.BackColor = Color.Black
If intval = 0 Then
intval = Me.Width
If intval2 = 0 Then
intval2 = Me.Height
gp.AddEllipse(New Rectangle(0, 0, intval, intval2))
Me.BackColor = Color.IndianRed
Region = New Region(gp)
Private Sub frmmain_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
NOTE: Select the Form type you want to create from the combobox. For Rounded rectangular form, enter the arc value, and hit create button.
For Circular form, enter the height and width, and hit create button.
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.
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.
- 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