VisualStyleState 枚举

定义

指定如何将视觉样式应用于当前应用程序。

此枚举支持其成员值的按位组合。

C#
public enum VisualStyleState
C#
[System.Flags]
public enum VisualStyleState
继承
VisualStyleState
属性

字段

ClientAndNonClientAreasEnabled 3

视觉样式应用于工作区和非工作区。

ClientAreaEnabled 2

视觉样式只应用于工作区。

NonClientAreaEnabled 1

视觉样式只应用于非工作区。

NoneEnabled 0

视觉样式不应用于应用程序。

示例

下面的代码示例是一个简单的程序,用于在值指定的 VisualStyleState 四个区域中应用视觉样式。 若要在特定区域中启用视觉样式,请单击选项按钮 (也称为单选按钮) 表示要启用的区域,然后单击“ 更新 VisualStyleState ”按钮以观察窗口中的更改。

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

注解

此属性使用此 Application.VisualStyleState 枚举来指定视觉样式是应用于应用程序窗口的客户端区域还是非封闭区域。

适用于

产品 版本
.NET Framework 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
Windows Desktop 3.0, 3.1, 5, 6, 7