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

.Net Win Forms Themes

, 8 Jul 2004
Rate this:
Please Sign up or sign in to vote.
Creating Custom theme/skins in .net require merely a few lines of code
<!-- Add the rest of your HTML here -->

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

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

About the Author

Chandra Hundigam
Architect
United States United States
Chandra Hundigam has Master degree in Computer Application, Microsoft Certified Professional and Software Architect. He's significantly involved in enterprise application development and distributed object oriented system development using Microsoft .Net, Sun Java/J2EE technology to serve global giants in the Media, Finance, Mortgage and Software Industries.Presently working as Independent Software Consultant for a US-based company.His areas of interests are in emerging Technologies.

Comments and Discussions

 
GeneralMy vote of 1 PinmemberRixterz1239-Jun-14 8:10 
QuestionC# thems Pinmemberdilan9125-Aug-12 23:27 
GeneralThis helped me create my custom theme! Thank you!!!! 5 stars! PinmemberTheRomanian18-Apr-11 5:01 
GeneralReply Pinmembercodertuhin2-Feb-09 5:52 
GeneralRe: Reply Pinmemberminhhaitpro12-May-11 15:08 
GeneralNice! PinmemberVJSWAMI4U5-Dec-08 20:19 
Generalupdated article PinmemberChandra Hundigam9-Jul-04 6:08 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 9 Jul 2004
Article Copyright 2004 by Chandra Hundigam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid