Application.EnableVisualStyles Application.EnableVisualStyles Application.EnableVisualStyles Application.EnableVisualStyles Method


為應用程式啟用視覺化樣式。Enables visual styles for the application.

 static void EnableVisualStyles();
public static void EnableVisualStyles ();
static member EnableVisualStyles : unit -> unit
Public Shared Sub EnableVisualStyles ()


下列程式碼範例將示範如何在 Main 函式中呼叫 EnableVisualStyles,以啟用應用程式的視覺化樣式。The following code example demonstrates calling EnableVisualStyles in the Main function to enable visual styles for the application.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace VStyles
   public ref class Form1: public System::Windows::Forms::Form
      System::Windows::Forms::Button^ button1;

         this->button1 = gcnew System::Windows::Forms::Button;
         this->button1->Location = System::Drawing::Point( 24, 16 );
         this->button1->Size = 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 = System::Drawing::Size( 300, 286 );
         this->Controls->Add( this->button1 );
         this->Text = "Application::EnableVisualStyles Example";



int main()
   Application::Run( gcnew VStyles::Form1 );

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

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

        private System.Windows.Forms.Button button1;
        static void Main() 
            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.Text = "Application.EnableVisualStyles Example";

Imports System.Drawing
Imports System.Windows.Forms

Namespace VStyles
    ' Summary description for Form1.
    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private button1 As System.Windows.Forms.Button

        <System.STAThread()> _
        Public Shared Sub Main()

            System.Windows.Forms.Application.Run(New Form1)
        End Sub

        Public Sub New()

            Me.button1 = New System.Windows.Forms.Button()
            Me.button1.Location = New System.Drawing.Point(24, 16)
            Me.button1.Size = New System.Drawing.Size(120, 100)
            Me.button1.FlatStyle = FlatStyle.System
            Me.button1.Text = "I am themed."

            ' Sets up how the form should be displayed and adds the controls to the form.
            Me.ClientSize = New System.Drawing.Size(300, 286)

            Me.Text = "Application.EnableVisualStyles Example"
        End Sub

    End Class
End Namespace 'VStyles


這個方法會啟用應用程式的視覺化樣式。This method enables visual styles for the application. 視覺化樣式是組成作業系統主題的色彩、字型和其他視覺元素。Visual styles are the colors, fonts, and other visual elements that form an operating system theme. 如果控制項和作業系統支援,控制項就會以視覺化樣式繪製。Controls will draw with visual styles if the control and the operating system support it. 若要產生效果,必須先呼叫 EnableVisualStyles(),才能在應用程式中建立任何控制項。一般來說,EnableVisualStyles() 是 @no__t 2 函式中的第一行。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. 呼叫 EnableVisualStyles() 時,不需要個別的資訊清單來啟用視覺化樣式。A separate manifest is not required to enable visual styles when calling EnableVisualStyles().


在 .NET Framework 2.0 之前,某些控制項的 FlatStyle 屬性(例如衍生自 ButtonBase 的控制項)必須設定為 FlatStyle.System,才能使用視覺化樣式繪製控制項。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. 在以 .NET Framework 2.0 撰寫的應用程式中,已不再需要這項功能。In applications written with the .NET Framework 2.0, this is no longer necessary.


這個方法不會影響 Internet Explorer 中裝載的控制項。This method will have no effect for controls hosted in Internet Explorer.