Page 1 of 5

Custom "Skin" for your forms

Posted: Fri Nov 27, 2009 5:27 am
by CodenStuff
Hello,

A few of you seem to be asking how to make a form with round edges and skin/theme and I think I have made a tutorial about this somewhere I cant seem to find it :? . I decided to write another one and explain how its done.

The first thing you need to do is open up our chosen paint software (I use microsoft paint as my choice) and start a new image. Your image dimensions need to be the same size as your form so make sure you set its size before you get started.

Then you get to work on creating our forms custom skin and for this example I just draw some basic shapes to show you:
sshot-21.png
Once you are happy with your design you need to choose a color that will become transparent when your application is run. I always use the color purple and have done so for this example. Once you have chosen your transparent color use it to fill in the areas of your skin that you dont want to show up when you run your application:
sshot-18.png
Now go into VB and change the followin properties on your form:

TransparencyKey - Change this to your transparent color (In my case I change it to purple)
FormBorderStyle - Change this to "None"
BackgroundImage - Change this to the skin you have just created.
Size - Make sure this is the same size as you skin
sshot-19.png
Thats the hard part done and we now move onto the code that will let you move your form.

Underneath "Public Class Form" add this code:
Code: Select all
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
    Public Const HTCAPTION As Integer = &H2
    <Runtime.InteropServices.DllImport("User32.dll")> _
    Public Shared Function ReleaseCapture() As Boolean
    End Function
    <Runtime.InteropServices.DllImport("User32.dll")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function
Then in the "Form_MouseDown" event add this code:
Code: Select all
If e.Button = MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
        End If
Build and run your project to see the results. If you did it all correctly then when you run your application it should look something like this:
sshot-20.png
Thats it your finished!!

You can do different designs of almost anything you want like one with round edges:
sshot-22.png
Or even a weird splatter shaped form:
sshot-23.png

These are the project files for this tutorial
Download:
CustomForm.zip
Happy coding! cooll;

Re: Custom "Skin" for your forms

Posted: Fri Nov 27, 2009 5:33 am
by TheET
WOW ! THank you very much ! I love this !

You are the best ! Woohoo Codenstuff rocks!!!!!!!

Re: Custom "Skin" for your forms

Posted: Fri Nov 27, 2009 8:27 am
by TheET
I try it but it still show a little bit purple , how can i remove that?

Re: Custom "Skin" for your forms

Posted: Fri Nov 27, 2009 10:36 am
by Nery
Yes, its a mistery, everytime you use that method, on the borders, you can see a line of your background color.

Re: Custom "Skin" for your forms

Posted: Sat Nov 28, 2009 4:19 am
by Robby
wow that is realli good. I GUESS NOW can make a templte so i ca use tht

Re: Custom "Skin" for your forms

Posted: Sat Nov 28, 2009 5:07 am
by NoWayIn
All I do is add a skin or picture, make it the same size and done :P

Re: Custom "Skin" for your forms

Posted: Sat Nov 28, 2009 4:00 pm
by CodenStuff
Hello,

Sometimes it still shows part of the transparent color on the edges I dont know why, mainly happens on curves.

Re: Custom "Skin" for your forms

Posted: Sun Nov 29, 2009 11:14 pm
by MasterCoding
gerryhill welcome to codenstuff

Re: Custom "Skin" for your forms

Posted: Sun Jan 24, 2010 12:25 pm
by tvs praveen
Hi, This tutorial is too helpful to me to create transparent splash screen background for my superb TV Broadcast, TV Playout Software!, Power TV Magic Express 18.2

Tell me do you like it or not? ;)

Image

Re: Custom "Skin" for your forms

Posted: Sun Jan 24, 2010 2:45 pm
by Usman55
Hello TVS Praveen!

It is just great! I wonder how people like Hungryhounduk (and you too) make designs like this? But whatever I say, this is wonderful!

Thanks for sharing!