new.gif

Introduction

This article shows you how to create forms with rounded corners. It will be helpful for those who wanted to create forms with rounded corners, in contrast to regular forms, but were stuck or could not understand how to do it? Now, there is no need to panic. This project will show you how to write a program that creates forms with rounded corners. Make your forms different from others and change the look of your application such that it will appeal to the user.

Using the Code

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

  • MaximizeBox: False
  • MinimizeBox: False
  • StartPosition: CenterScreen
  • Size: 400,350
  • FormBorderStyle: None

Now, click on "View Code" and write the following code in Form1's paint method, i.e., write the method "Form1_Paint".

Public Class  Form1

    Private Sub Form1_Paint(ByVal sender As Object, _
	ByVal e As  System.Windows.Forms.PaintEventArgs) Handles  Me.Paint
        Dim gp As New System.Drawing.Drawing2D.GraphicsPath
        Dim r1 As New Rectangle(0, Me.Height - 20, 20, 20)
        Dim r2 As New Rectangle(Me.Width - 21, Me.Height - 20, 20, 20)

		'Creating Arc top-left and top-right
        gp.AddArc(0, 0, 20, 20, 180, 90)
        gp.AddArc(Me.Width - 21, 0, 20, 20, 270, 90)


        gp.AddRectangle(New Rectangle(0, 10, Me.Width, Me.Height - 20))

		'Creating Arc bottom-left and bottom-right
        gp.AddArc(r1, -270, 90)
        gp.AddArc(r2, 360, 90)

			'Change the color of the form
        Me.BackColor = Color.Black
        Region = New Region(gp)
    End Sub

   'Now code for closing the Form1 

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

Motive

The motive of posting this article was to help those who want to create rounded forms, but were unable to get any help. This is because 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.

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架