Skybound VisualStyles

1. Enabling VisualStyles

This topic describes the first steps necessary for building an application with Skybound VisualStyles.

Key Concepts

The key concepts of this topic are:

Adding a reference to the Skybound VisualStyles assembly

If you are using Microsoft Visual Studio .NET®, you will need to add a reference to Skybound.VisualStyles.dll to your project before using it.

  1. From the Project menu, choose Add Reference.

  2. VS.NET 2002/2003: Ensure the .NET tab is selected, and click the Browse button.
    VS.NET 2005: Ensure the Browse tab is selected.
  3. Navigate to the directory where Skybound VisualStyles is installed (the default is C:\Program Files\Skybound VisualStyles). Double-click on Skybound.VisualStyles.dll.
  4. Click OK.

Other visual IDEs may have different ways of referencing assemblies. You should consult the product documentation included with the IDE for instructions.

Enabling VisualStyles

This section describes the steps necessary to enable VisualStyles in your application.

Enabling VisualStyles in C#

VisualStyles is enabled by adding one line of code to your application's Main() method. In Visual Studio 2002 and 2003, this method is created in your startup form by default. In Visual Studio 2005, this method is in Program.cs by default.

[C#]

using (Skybound.VisualStyles.VisualStyleContext.Create())
  Application.Run(new Form1())

Enabling VisualStyles in Visual Basic 2005

To use VisualStyles, you must handle the application startup event.

From the Project menu, click Properties, then the View Application Events button. Add the following code to that class:

[VB.NET 2.0]

Shared VSContext As Skybound.VisualStyles.VisualStyleContext

Public Sub HandleStartup(ByVal sender As Object, ByVal e As ApplicationServices.StartupEventArgs) _
  Handles Me.Startup
  
  VSContext = Skybound.VisualStyles.VisualStyleContext.Create
End Sub

Enabling VisualStyles in Visual Basic 2002/2003

To use VisualStyles, your application must start from Sub Main.

By default, all Visual Basic applications start using a Startup Form. To switch your application to Sub Main, follow these 3 steps:

  1. From the Project menu, click Properties.
  2. Change the Startup Object to Sub Main, and then click OK.
  3. Add the following code anywhere in your application:

[VB.NET 1.x]

Shared VSContext As Skybound.VisualStyles.VisualStyleContext

Public Shared Sub Main()
  VSContext = Skybound.VisualStyles.VisualStyleContext.Create
  Application.Run(New Form1)
End Sub

If your application is already has a Sub Main, just add the green lines in the code above to the existing class.

Using a VisualStyleFilter to specify which controls are enhanced

First, add the VisualStyleFilter component to the toolbox. In Visual Studio .NET, this is done by:

  1. On the View menu, choose Toolbox to display the toolbox if it is not already visible.
  2. Right-click on the toolbox and choose Add/Remove Items (2002/2003) or Choose Items (2005).

  3. Click Browse. Navigate to the directory where you installed Skybound VisualStyles. Choose the file Skybound.VisualStyles.dll.
  4. Click OK on the Add/Remove Items window to complete the operation. The VisualStyleFilter component now appears at the bottom of the list of components in the toolbox.

Other visual IDEs may have different ways of adding custom components to the toolbox. You should consult the product documentation included with the IDE for instructions.

Once a VisualStyleFilter component has been added to a form designer, all controls receive a new property called VisualStyleEnhanced. Set the value of this property to Yes to force a control to be enhanced, No to prevent it from being enhanced, or Default to cause it to use the application-wide default setting

NOTE: The application-wide default setting is set with the SetEnhancedDefault static (Shared in Visual Basic) method.

Specifying which controls are enhanced in code

It is not necessary to create a VisualStyleFilter component unless you are using a forms designer. At runtime, the VisualStyleFilter.Global object is available at all times for the same purpose.

This example prevents a control called textBox1 from being enhanced:

[C#]

VisualStyleFilter.Global.SetVisualStyleEnhanced(textBox1, VisualStyleEnhanced.No);

[Visual Basic]

VisualStyleFilter.Global.SetVisualStyleEnhanced(textBox1, VisualStyleEnhanced.No)