Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How to modify the Shape of Windows Form Using Visual Basic.Net

Author: DevASP
Download Source Code :

This article is about how you can create your own shaped form in By default the shape of your form is rectangular but in some situations you may want to change this shape.

  • Steps you will do. 
  • Start visual studio and create a new window application 
  • Set the following properties of form.

BackgroundImage = “image file for shape of your form”

FormBoarderStyle = None


  • From toolbox drop a tool tip control on your form. 
  • Drop a picture box control on your form and set the following properties.

Name = pb

Image = “image file use for close button”

Backcolor = Transparent

Tooltip = “Close”


  • Drop a label control on the form and set the following properties.

Name = lbl

Text = “Shaped Form”

Backcolor = Transparent

Forecolor = White


  • Drop a button control on your form and set its following properties.

Name = btMsg

Text = Click Me

Tooltip = “Click to show a message”

Backcolor = Transparent

Forecolor = White

  • Open your code window and declare the following functions to use window API’s  as below.

Private Declare Sub ReleaseCapture Lib "user32" ()


Private Declare Sub SendMessage Lib "user32" Alias "SendMessageA" (ByVal _

hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _

ByVal lParam As Integer)


Private Const WM_NCLBUTTONDOWN As Integer = &HA1


Private Const HTCAPTION As Integer = 2


  •  In the paint event of the form write the following code.

Dim img As Bitmap = Me.BackgroundImage

      img.MakeTransparent(img.GetPixel(0, 0))

      Me.TransparencyKey = img.GetPixel(0, 0)


  • In the click event of the picture box write the following code.




  • In the mouse down event of the form write the following code so that you can move the shaped form.

If e.Button = MouseButtons.Left Then


   SendMessage(Me.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0&)

End If


Article Comments
i tried this code in 2005 but it doesn't work can u help me

Posted on 5/16/2007 6:03:39 PM by samah

very useful for your notes for me.

Posted on 3/6/2008 1:38:21 AM by guna

I tried this code in, it can't be resize the form in runtine, but how to modify the shape of the form? plz help me

Posted on 3/12/2008 1:32:29 AM by ruba

I tried this code in, by using this i can't be able to resize he form in runtime,but how to modify the form shape? plz help...

Posted on 3/12/2008 1:34:43 AM by ruba

I want to know how we can change the form shape like window media player etc.
please tell me .

Posted on 3/27/2008 9:00:09 AM by Kuldeep

This code works fine guys. I've only been doing programming for 3 weeks and I got it to i'm sure the rest of you can. You just need to remove all the line spaces if you copied and pasted this code. Also, I noticed that it only makes the black color transparent. If you play around with the image you will soon figure out how to adjust it to get the shape you want.

Posted on 11/10/2008 5:20:00 PM by richard

Add Article Comment:
Name :
Email Address :
Comments :
<< How to Change the Caps of String in Visual Basic.Net

Disclaimer - Privacy
© 2002-2017