Click here to Skip to main content
Click here to Skip to main content

Adding custom skins for Forms in VB.Net

By , 12 Jun 2008
 

Introduction

In this project I have created an User control which can be used in Windows Form applications in VB.NET. Using this control you can add a New look to your Forms. I wont say this as a perfect code and method for adding skins, But there may be other ways which are better than this. I believe this as a simple way for adding skins to Win Forms.
Form-Skin.gif
Download Form_Skin.zip - 218.2 KB

Background

I was searching for some free skinner control to add for my Project. But I didnt find anything. Finally I got a small clue in a website to create skins. Thanks for that author. This control is fully made of panel controls. And I created the images for this skin in Photoshop. May or may not similar codes are available in the Code Project. Feel free to contact me for any suggestions about this control. You can get any help from me through e-mail.

Using the code

No special coding is needed for using this control. Just add the control in your Toolbox by Right clicking on the toolbox and selecting Choose Items and then Skinner.dll from the location you have stored. After this the Control is ready to use and you can drag and drop the control in the form to use this control. The Caption for the skinned form is read from the Form's text property. The icon is also taken from the icon which is set to the original form. The form's background is set to Transparent by using the Transparency key property. This will be set by the Skinner control. The following line shows this

 Me.ParentForm.TransparencyKey = System.Drawing.Color.FromArgb(121, 121, 121)
        

Remember to set the Language of your code snippet using the Language dropdown.

History

This is the predecessor version for my Skin controls in VB.NET. 6 April 2008. You can expect for the updated version soon with lots of improvements and almost all functionalities of a form like changing the position of form by dragging the title bar.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ferminus Muthu
Technical Lead Endeavour Software Technologies
India India
Member
I am working as a Technical Lead in Bangalore. I started my development career using VB 6.0. I was interested in creating windows based applications. Later I worked on web based applications with ASP.Net. Now I am working in WCF web services for Iphone and Ipad applications.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionThanksmemberMuslim Bahdili11 Apr '13 - 18:54 
THannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnk you Big Grin | :-D
GeneralMy vote of 5memberJack_32115 May '12 - 1:21 
it really helped me to get started ...
GeneralMy vote of 5memberCJ736 Mar '12 - 18:11 
Very good work.
GeneralMy vote of 5membermanoj kumar choubey19 Feb '12 - 23:24 
Nice
GeneralMy vote of 3memberSwelihle30 Aug '11 - 23:15 
just the Skinner.dll is not explained.
QuestionExcellent ideamemberjlkdaslkfjd22 Aug '11 - 0:36 
Panels are a great way, I never considered it! Thank you!
Generalform skinningmemberTeddyW18 Jun '11 - 0:02 
first of all i would like u to appropriate the effort that u made.
 
the problem that i am facing is i was trying to add a panel which doc style is filled on the parent form, but unfortunately the custom form is fill by the back the panel and am not able to see the form please help.
GeneralGreat article my friend! It helped me at..memberTheRomanian18 Apr '11 - 4:17 
Your article was of great help for my programmer brother. It helped me a lot!
I rated it excelent.
How old is the Orthodox Faith?
http://www.orthodoxphotos.com/history.shtml
 

If you are a Lutheran, your religion was founded by Martin Luther, an ex-monk of the Catholic Church, in the year 1517. If you belong to the Church of England, your religion was founded by King Henry VIII in the year 1534 because the Pope would not grant him a divorce with the right to re-marry. If you are a Presbyterian, your religion was founded by John Knox in Scotland in the year 1560. If you are a Congregationalist, your religion was originated by Robert Brown in Holland in 1582. If you are Protestant Episcopalian, your religion was an offshoot of the Church of England, founded by Samuel Senbury in the American colonies in the 17th century. If you are a Baptist, you owe the tenets of your religion to John Smyth, who launched it in Amsterdam in 1606. If you are of the Dutch Reformed Church, you recognize Michelis Jones as founder because he originated your religion in New York in 1628. If you are a Methodist, your religion was founded by John and Charles Wesley in England in 1774. If you are a Mormon (Latter Day Saints), Joseph Smith started your religion in Palmyra, New York, in 1829. If you worship with the Salvation Army, your sect began with William Booth in London in 1865. If you are Christian Scientist, you look to 1879 as the year in which your religion was born and to Mary Baker Eddy as its founder.
 
If you belong to one of the religious organizations known as "Church of the Nazarene, Pentecostal Gospel," "Holiness Church," or "Jehovah's Witnesses," your religion is one of the hundreds of new sects founded by men within the past hundred years.
 
If you are Roman Catholic, your church shared the same rich apostolic and doctrinal heritage as the Orthodox Church for the first thousand years of its history, since during the first millennium they were one and the same Church. Lamentably, in 1054, the Pope of Rome broke away from the other four Apostolic Patriarchates (which include Constantinople, Alexandria, Antioch and Jerusalem), by tampering with the Original Creed of the Church, and considering himself to be infallible. Thus your church is 1,000 years old.
 
If you are Orthodox Christian, your religion was founded in the year 33 by Jesus Christ, the Son of God. It has not changed since that time. Our church is now almost 2,000 years old. And it is for this reason, that Orthodoxy, the Church of the Apostles and the Fathers is considered the true "one Holy Catholic and Apostolic Church." This is the greatest legacy that we can pass on to the young people of the new millennium.

GeneralHelpmembersteve02113 Apr '11 - 5:20 
how can i use this in my application
GeneralWhatsthishelpbuttonmemberMember 324988420 Sep '10 - 2:44 
Hello Ferminus,
very good sample code.
Just a question...
I tring to enable behavior for HelpButtonClicked event (PictureBox5_Click)...
Any suggestions for doing that ?
 
Thank in advance and again my compliments.
GeneralMy vote of 5memberFreshbrew28 Aug '10 - 0:34 
Simple, excellent and just what I was looking for! Kudos.
GeneralProblem with window state at runtimememberusha gupta19 Jul '10 - 2:47 
HI
 
REALLY NICE ARTICLE!!!
 
BUT I AM FACING SOME PROBLEM.PLEASE HELP ME.
 

 

WHEN WE RUN OUR FORM WITH THIS SKIN IT TURNS BLACK FOR SOMETIME AND AFTER THAT SKIN SHOWS.BUT WHEN WE CHANGE THE STATE OF FORM MAXIMIZED IT'S WORKING FINE AT RUNTIME,
 

PLEASE HELP ME.
ushagupta

GeneralC# version and Thanks a Ton...memberMember 469050514 Feb '10 - 9:36 
Hi, First of all,,Great idea.Just like web-application.. Smile | :)
C# Code.
 
public partial class FormSkin : UserControl
      {
            int bit;
            Point p1 = default(Point);
            Point p2 = default(Point);
            public FormSkin()
            {
                  InitializeComponent();
            }
 
            private void FormSkin_Load(object sender, EventArgs e)
            {
                  this.ParentForm.FormBorderStyle = FormBorderStyle.None;
                  this.Dock = DockStyle.Fill;
                  this.ParentForm.TransparencyKey = System.Drawing.Color.FromArgb(121, 121, 121);
                  this.label1.Text = this.ParentForm.Text;
            }
 
            private void FormSkin_Paint(object sender, PaintEventArgs e)
            {
                  this.SendToBack();
            }
 
            private void panel5_MouseMove(object sender, MouseEventArgs e)
            {
                  if (bit == 1)
                  {
                     this.ParentForm.Location = new Point(this.ParentForm.Location.X + (e.Location.X - p2.X), this.ParentForm.Location.Y (e.Location.Y - p2.Y));
                  }
 
            }
 
            private void panel5_MouseUp(object sender, MouseEventArgs e)
            {
                  bit = 0;
            }
 
            private void panel5_MouseDown(object sender, MouseEventArgs e)
            {
                  bit = 1;
                  p1 = this.ParentForm.Location;
                  p2 = e.Location;
            }
 
            private void pictureBox5_Click(object sender, EventArgs e)
            {
                  this.ParentForm.Close();
            }
 
            private void pictureBox6_Click(object sender, EventArgs e)
            {
                  Form f1 = this.ParentForm.MdiParent;
              
            }
      }
GeneralRe: C# version and Thanks a Ton...memberFerminus Muthu7 Mar '10 - 22:39 
Thanks for C# version of the code.
GeneralRe: C# version and Thanks a Ton...memberPriya Billava30 Mar '10 - 18:57 
Hi ,
 
Great stuff. please can u help in changing the colur of the skin and how can it be achived?
GeneralSomething More Challenging...memberJoshua Eiland13 Feb '10 - 19:37 
This works very well, and does a great job, too!
 
Now could we develop it enough to skin message boxes as well? That may be out of this control's scope, though.
GeneralRe: Something More Challenging...memberFerminus Muthu7 Mar '10 - 22:38 
I should think of working for it
GeneralMy vote of 1memberseinkraft24 Jan '10 - 5:32 
No explanation of the code or concepts in the article
Generalhi..... gr8 stuffmemberArunabh Nag22 Jul '09 - 12:30 
but if the skinner is added twice to a form by mistake,
a cyclic redundancy starts crashing the dev-env
GeneralGreat start.....memberDJ Matthews17 Jul '09 - 9:49 
The only thing missing for this is the ability to add some sort of custom theme file that tells your control how to skin itself and the ability to resize the form using the control.
 
I am currently adding the ability to resize the form.... it's just that it looks bad with all of the flickering in the form panels.
QuestionHow did you make it??membervietnam_boi_967 Jul '09 - 13:34 
Hi.... I was just wondering about how you made it because it looks so cool and I think maybe I could make my own....
 
vietnam_boi_96
Generalthanksmemberagdeniz17 May '09 - 20:47 
Your article was very good and usefull for me . a long time i was searching for this sample thanks a lot
Agdeniz from Iran
GeneralMy vote of 1mvpDave Kreskowiak30 Jan '09 - 10:07 
No explanation of the code or concepts in the articl content.
GeneralForm Stretch problemmemberMember 369554613 Jan '09 - 20:01 
Hi,
 
The forms is stretched in a way that gaps are visible between the panels which then appears transparent in the gaps. I tried to play around with my screen resolution, but the gaps remain. Does anyone have had a similar problem with a possible solution?
 
Regards
GeneralRe: Form Stretch problemmemberawparso25 Oct '11 - 11:17 
since the widths are specified as specific widths, you'll have to handle the resize event from the base form/usercontrol in order to stretch the desired panel to fill the gaps between the static sized panels to fix this. not hard, but an extra step.
Generalsugestionmemberrio_p7 Nov '08 - 3:43 
its cool, but to reduce flicker when windows is moving, you should use double buffered picture box and panel, you should create new class to declare double buffered control
here's the code:
------------------------------
Public Class BuferedPictureBox
    Inherits PictureBox
    Public Sub New()
        MyBase.New()
        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer, True)
    End Sub
End Class
 
Public Class BuferedPanel
    Inherits Panel
    Public Sub New()
        MyBase.New()
        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer, True)
    End Sub
End Class
------------------------------
I try to your application and it work!! Big Grin | :-D ,
you just replace "system.windows.Form.PictureBox" in Form skin.Designer.vb to "BuferedPictureBox"
and replace "System.Windows.Form.Panel" in Form skin.Designer.vb to "BuferedPanel"
and it work!
Good Job!!! Big Grin | :-D
GeneralRe: sugestionmemberArmando Airo'14 Nov '08 - 8:11 
Thank You for your Post!!!
 
Arma74

GeneralRe: sugestionmemberwolf9s28 Jul '11 - 0:18 
It's great!
I find that it's frequently flick when drag it and moving,too.
So I read every discuss, eventually, I find this.3Q.
GeneralFlickering Problem!memberfarizvi17 Jul '08 - 20:49 
The form flickers when it is dragged. Haven't you found any solution for it?
GeneralBug still there!membersjcardinale12 Jun '08 - 10:37 
Form still jumps around while moving with the mouse.
GeneralBug correctedmemberFerminus Muthu12 Jun '08 - 1:44 
Hi friends, I have corrected the small bug which my form had while dragging. Thanks to Selvin.
GeneralRe: Bug correctedmemberSelvin12 Jun '08 - 2:18 
maybe ... but now source code is gone :P
 
...works fascinates me...i can stare it for hours...

GeneralRe: Bug correctedmembermscdex12 Jun '08 - 6:04 
No, it's there underneath the screenshot Smile | :)
GeneralRe: Bug correctedmemberwolf9s28 Jul '11 - 0:21 
But, do you update it?
General[Message Removed]memberMojtaba Vali25 May '08 - 0:50 
Spam message removed
GeneralSmall bugmemberSelvin21 May '08 - 4:30 
just change
    Private Sub Panel5_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel5.MouseMove
        If bit = 1 Then
            Me.ParentForm.Location = p1 + (e.Location - p2)
            p2 = e.Location
            p1 = Me.ParentForm.Location
        End If
    End Sub
with
    Private Sub Panel5_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel5.MouseMove
        If bit = 1 Then
            Me.ParentForm.Location += (e.Location - p2)
            'p2 = e.Location
            'p1 = Me.ParentForm.Location
        End If
    End Sub
now u dont need p1 and form moving should works fine
 
...works fascinates me...i can stare it for hours...

GeneralcoolmemberAbhijit Jana9 May '08 - 23:45 
nice article
5 from me
 
Best Regards
-----------------
Abhijit Jana
"Success is Journey it's not a destination"

GeneralMoving the skinned formmemberKong Ragge6 May '08 - 23:58 
Looked fine until I tried to move the form. Then the form starts to jump up/down/sideways and does not follow the mouse cursor. When I add a regular form, it moves just fine.
It definitely does need some more work to get stable moving of the form.
I'm using Vista 64-bit but I have not seen any other program behave this way.
 
Keep up the good work. I really liked this idea and I have been looking for something like this for some time now.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 12 Jun 2008
Article Copyright 2008 by Ferminus Muthu
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid