Application.EnableVisualStyles 方法

定义

启用应用程序的可视样式。

C#
public static void EnableVisualStyles();

示例

下面的代码示例演示如何在 函数中Main调用 EnableVisualStyles 以启用应用程序的视觉样式。

C#
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";
        }
    }
}

注解

此方法为应用程序启用视觉样式。 视觉样式是构成操作系统主题的颜色、字体和其他视觉元素。 如果控件和操作系统支持控件,控件将使用视觉样式进行绘制。 若要生效, EnableVisualStyles() 必须在应用程序中创建任何控件之前调用 ;通常, EnableVisualStyles() 是 函数中的 Main 第一行。 调用 EnableVisualStyles()时,不需要单独的清单即可启用视觉样式。

备注

此方法对 Internet Explorer 中托管的控件不起作用。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅