Export (0) Print
Expand All
Expand Minimize

VisualStyleState Enumeration

Specifies how visual styles are applied to the current application.

Namespace:  System.Windows.Forms.VisualStyles
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public enum VisualStyleState

Member nameDescription
ClientAndNonClientAreasEnabledVisual styles are applied to client and nonclient areas.
ClientAreaEnabledVisual styles are applied only to the client area.
NonClientAreaEnabledVisual styles are applied only to the nonclient area.
NoneEnabledVisual styles are not applied to the application.

This enumeration is used by the Application.VisualStyleState property to specify whether visual styles are applied to client or nonclient areas of application windows.

The following code example is a simple program that applies visual styles in each of the four areas specified by the VisualStyleState values. To enable visual styles in a certain area, click the option button (also known as a radio button) that represents the area you want to enable, and click the Update VisualStyleState button to observe the changes in the window.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace VisualStyleStateSample
{
	class Form1 : Form
	{
		Button button1 = new Button();
		RadioButton radioButton1 = new RadioButton();
		RadioButton radioButton2 = new RadioButton();
		RadioButton radioButton3 = new RadioButton();
		RadioButton radioButton4 = new RadioButton();

		public Form1()
		{
			button1.AutoSize = true;
			button1.Location = new Point(10, 10);
			button1.Text = "Update VisualStyleState";
			button1.Click += new EventHandler(button1_Click);

			radioButton1.Location = new Point(10, 50);
			radioButton1.AutoSize = true;
			radioButton1.Text = "Apply styles to client area only";

			radioButton2.Location = new Point(10, 70);
			radioButton2.AutoSize = true;
			radioButton2.Text = "Apply styles to nonclient area only";

			radioButton3.Location = new Point(10, 90);
			radioButton3.AutoSize = true;
			radioButton3.Text = "Apply styles to client and nonclient areas";

			radioButton4.Location = new Point(10, 110);
			radioButton4.AutoSize = true;
			radioButton4.Text = "Disable styles in all areas";

			this.Text = "VisualStyleState Test";
			this.Controls.AddRange(new Control[] { button1,  
                radioButton1, radioButton2, radioButton3, radioButton4});
		}

		[STAThread]
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}

		void button1_Click(object sender, EventArgs e)
		{
			if (radioButton1.Checked)
			{
				Application.VisualStyleState =
					VisualStyleState.ClientAreaEnabled;
			}
			else if (radioButton2.Checked)
			{
				Application.VisualStyleState =
					VisualStyleState.NonClientAreaEnabled;
			}
			else if (radioButton3.Checked)
			{
				Application.VisualStyleState =
					VisualStyleState.ClientAndNonClientAreasEnabled;
			}
			else if (radioButton4.Checked)
			{
				Application.VisualStyleState =
					VisualStyleState.NoneEnabled;
			}

			// Repaint the form and all child controls. 
			this.Invalidate(true);
		}
	}
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft