By default VisualStyler will automatically embed the selected visual style into your applications at design-time, and you do not need to write any code. This behaviour is controlled by the SaveAsResource setting on the component designer, if this is set to false then you will need to deploy the skin file separately.

However you might want to provide your users with a choice of skins, and this is very easy to do, in the following example we have a simple application that provides two skins at runtime. Both skins are embedded into the application and are loaded when the user clicks the appropriate button, you will need to carry the following tasks :-


Example solution layout

  • Create a folder 'Skins' in the root of your application solution.
  • Select the folder and right-click Add->Add Existing Item.
  • In the file dialog navigate to the skins folder and select one or more skins, and click OK.
  • Bring the properties window up and for each file set the 'Build Action' to 'Embedded Resource'.



Example C# code

The following sample code is taken from the main form above, and as you can see when each button is clicked, we simply obtain the resource stream for each skin and then use the VisualStyler LoadVisualStyle method to load directly from the stream. Using this method you can ship any number of VisualStyler skins with your application.

using System; using System.Reflection; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //<-------------------------------------------------------------------> /// <summary> /// Handles the LoadVistaAeroSkin button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoadVistaAeroSkin_Click(object sender, EventArgs e) { // Get the resource path for the Aero skin string skinName = @"WindowsApplication1.Skins.Vista (Aero).vssf"; // Load the skin directly from the resource stream visualStyler1.LoadVisualStyle(Assembly.GetExecutingAssembly().GetManifestResourceStream(skinName)); } //<-------------------------------------------------------------------> /// <summary> /// Handles the LoadAquaSkin button click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoadAquaSkin_Click(object sender, EventArgs e) { // Get the resource path for the Aqua skin string skinName = @"WindowsApplication1.Skins.OSX (Aqua).vssf"; // Load the skin directly from the resource stream visualStyler1.LoadVisualStyle(Assembly.GetExecutingAssembly().GetManifestResourceStream(skinName)); } } }


Example VB.Net code

The code for Visual Basic is identical except that Visual Basic stores assembly resources differently than C#, in Visual Basic the resource is accessed through the root namespace and then the resource name i.e MyApplication.MySkin.vssf, where as resources in C# are accessed using there fully qualified name.

Imports System Imports System.Reflection Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Text Imports System.Windows.Forms Namespace WindowsApplication1 Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub '<-------------------------------------------------------------------> ''' <summary> ''' Handles the LoadVistaAeroSkin button click event ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> Private Sub btnLoadVistaAeroSkin_Click(ByVal sender As Object, ByVal e As EventArgs) ' Get the resource path for the Aero skin Dim skinName As String = "WindowsApplication1.Vista (Aero).vssf" ' Load the skin directly from the resource stream visualStyler1.LoadVisualStyle(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(skinName)) End Sub '<-------------------------------------------------------------------> ''' <summary> ''' Handles the LoadAquaSkin button click event ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> Private Sub btnLoadAquaSkin_Click(ByVal sender As Object, ByVal e As EventArgs) ' Get the resource path for the Aqua skin Dim skinName As String = "WindowsApplication1.OSX (Aqua).vssf" ' Load the skin directly from the resource stream visualStyler1.LoadVisualStyle(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(skinName)) End Sub End Class End Namespace