Export (0) Print
Expand All

Application.EnableVisualStyles Method

Enables visual styles for the application.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public static void EnableVisualStyles ()
public static void EnableVisualStyles ()
public static function EnableVisualStyles ()

This method enables visual styles for the application. Controls will draw with visual styles if the control and the operating system support it. To have an effect, EnableVisualStyles must be called before creating any controls in the application; typically, EnableVisualStyles is the first line in the Main function. A separate manifest is not required to enable visual styles when calling EnableVisualStyles.

NoteNote

Prior to the .NET Framework 2.0, the FlatStyle property of some controls, such as controls that derive from ButtonBase, had to be set to FlatStyle.System in order for the controls to be drawn with visual styles. In applications written with the .NET Framework 2.0, this is no longer necessary.

NoteNote

This method will have no effect for controls hosted in Internet Explorer.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: Visual styles are only supported on these platforms.

The following code example demonstrates calling EnableVisualStyles in the Main function to enable visual styles for the application.

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

namespace VStyles
{
    public class Form1 : System.Windows.Forms.Form
    {

        private System.Windows.Forms.Button button1;
        
        [STAThread]
        static void Main() 
        {
            Application.EnableVisualStyles();
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button1.Location = new System.Drawing.Point(24, 16);
            this.button1.Size = new System.Drawing.Size(120, 100);
            this.button1.FlatStyle = FlatStyle.System;
            this.button1.Text = "I am themed.";

            // Sets up how the form should be displayed and adds the controls to the form.
            this.ClientSize = new System.Drawing.Size(300, 286);
            this.Controls.Add(this.button1);

            this.Text = "Application.EnableVisualStyles Example";

        }
    }
}

package VStyles;
 
import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends System.Windows.Forms.Form
{
    private System.Windows.Forms.Button button1;

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    } //main

    public Form1()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.button1.set_Location(new System.Drawing.Point(24, 16));
        this.button1.set_Size(new System.Drawing.Size(120, 100));
        this.button1.set_FlatStyle(FlatStyle.System);
        this.button1.set_Text("I am themed.");
        // Sets up how the form should be displayed and adds the controls 
        // to the form.
        this.set_ClientSize(new System.Drawing.Size(300, 286));
        this.get_Controls().Add(this.button1);

        this.set_Text("Application.EnableVisualStyles Example");
    } //Form1 
} //Form1

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft