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  WinForm before selecting Theme
Fig  WinForm after selecting Theme1
Fig  WinForm 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.
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.