Application.EnableVisualStyles方法

本文介绍如何使用.NET Framework中的Application.EnableVisualStyles方法为Windows Forms应用程序启用视觉样式。该方法需在创建任何控件之前调用,以确保控件能够利用操作系统的视觉主题进行渲染。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Application.EnableVisualStyles 方法

.NET Framework 3.0
启用应用程序的可视样式。

命名空间: System.Windows.Forms
程序集: System.Windows.Forms(在 system.windows.forms.dll 中)

public:
static void EnableVisualStyles ()
J#
public static void EnableVisualStyles ()
public static function EnableVisualStyles ()
不适用。

此方法为应用程序启用可视样式。如果控件和操作系统支持视觉样式,则控件将以视觉样式进行绘制。若要使 EnableVisualStyles 生效,必须在应用程序中创建任何控件之前调用它;EnableVisualStyles 通常是 Main 函数的第一行。当调用 EnableVisualStyles 时,无需单独的清单即可启用可视化样式。

说明注意:

在 .NET Framework 2.0 之前的版本中,必须将某些控件(如从 ButtonBase 派生的控件)的 FlatStyle 属性设置为 FlatStyle.System,以便使用可视样式绘制控件。如果应用程序是使用 .NET Framework 2.0 编写的,则无需此操作。

说明注意:

此方法不会影响 Internet Explorer 中承载的控件。

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 平台说明: 只有这些平台支持可视样式。

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

#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
   {
   private:
      System::Windows::Forms::Button^ button1;

   public:
      Form1()
      {
         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";
      }

   };

}


[STAThread]
int main()
{
   Application::EnableVisualStyles();
   Application::Run( gcnew VStyles::Form1 );
}


J#
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 Server 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

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

.NET Framework
受以下版本支持:3.0、2.0、1.1
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值