Click here to Skip to main content
15,868,016 members
Articles / Programming Languages / Visual Basic
Article

.Net Win Forms Themes

Rate me:
Please Sign up or sign in to vote.
3.00/5 (24 votes)
8 Jul 20042 min read 260.5K   11K   57   8
Creating Custom theme/skins in .net require merely a few lines of code

Introduction

The article focuses on creating themes in VB.net Win Forms. As we know many times in much application we see different style of forms and its shape, for example windows media player where you change the form style or in another words its skin.

And many times in GUI development we need something different style and shape for the win forms.  A theme is basically changing the appearance of the form and its representation. In some cases themes are also called as skins. In .net it’s pretty simple to implement non-rectangle forms.

In order to implement this concept I have used pretty simple example where you can see that when you select a theme from the combo box it automatically changes complete presentation.

The sample with this article is self explanatory and simple. In order to implement non-rectangular forms we need to do following steps.

Step1: Create a .jpg file that will be used to set the forms background

Step2:  Create a Windows Application project and set properties to use the .jpg as the
            background of the form and get rid of the title bar.

Step3: Using GraphicsPath Object change the forms shape

Step4: Add the code for moving the form and closing it.

In this sample I created a class called Theme. And Theme1, Theme2 are derived classes of Theme. Each does its own implementation of Theme. When user selects the theme from combo box in the form, The Form appearance changes as theme is changed.

Below Figures shows the sample application functionality.

Fig [1] WinForm before selecting Theme

Winform befor selecting Theme

Fig [2] WinForm after selecting Theme1
 

winform after selecting Theme1

Fig [3] WinForm after selecting Theme2

Winforms after selecting Theme2

 

In the sample Application class 'Theme" is the base class which has two properties

1.BackGroundImage: Which holds the background image for the form

2.TransperncyColor: Which holds the transperancy color for the form

(one can extend the class with more properties if needed)

and a MustOverride method called

1.SetTheme(ByRef frmObj As Form) : The derived class must override this method and do implementation of theme. In the sample application, there are two derived classes called "Theme1" and "Theme2". Each does different implementation of theme.

Class "Theme1" concentrates on displaying form as shown in figure1 above<o:p>

And Class "Theme2" concentrates on displaying form as shown in figure2 above.

Code beneth the SetTheme(ByRef frmObj As Form) method of class Theme1 and Theme2 are pretty self explanatory.

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
United States United States
Chandra Hundigam-Venkat has Master degree in Computer Application, Microsoft Certified Professional and Cloud & Software Architect. Significantly involved in Cloud solutions, Cloud native application, Cloud migration, Enterprise application development distributed object oriented system development. Started computer career at the early age of eighteen as an intern in computer labs and had the opportunity to work with various USA fortune 500 companies in various technology and leadership roles.


Comments and Discussions

 
QuestionNice, but mouse handling is a little bit bad Pin
Axel Steiner2-Aug-15 14:26
Axel Steiner2-Aug-15 14:26 
GeneralMy vote of 1 Pin
Rixterz1239-Jun-14 8:10
Rixterz1239-Jun-14 8:10 
QuestionC# thems Pin
dilan9125-Aug-12 23:27
dilan9125-Aug-12 23:27 
how to add C# thems in C# Project
GeneralThis helped me create my custom theme! Thank you!!!! 5 stars! Pin
TheRomanian18-Apr-11 5:01
TheRomanian18-Apr-11 5:01 
GeneralReply Pin
codertuhin2-Feb-09 5:52
codertuhin2-Feb-09 5:52 
GeneralRe: Reply Pin
minhhaitpro12-May-11 15:08
minhhaitpro12-May-11 15:08 
GeneralNice! Pin
cpparasite5-Dec-08 20:19
cpparasite5-Dec-08 20:19 
Generalupdated article Pin
Chandra Hundigam Venkat9-Jul-04 6:08
Chandra Hundigam Venkat9-Jul-04 6:08 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.