网上冲浪 | 反毒杀毒 | 菜鸟进阶 | 网络安全 | 实用技术 | 网络安全 | 操作系统 |
工具软件 | 电脑医院 | 网上赚钱 | 网页制作 | 网络营销 | 经典教程 | IT趣 谈 |
当前位置:IT快活林快活林学院数据结构

C# 中WindowsForm 的初始化信息 [STAThread]

  static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new Form1());

        }

 

 

    }

 

以上的代码是VS 2005中默认的初始化信息.

Application.EnableVisualStyles();

简单的说就是让你的控件显示出来.当然是在WindowsForm 中

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

 

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

  对于支持   FlatStyle   属性的控件,请确保将   FlatStyle   属性设置为   FlatStyle.System   值。  

 

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";

 

        }

    }

}

 

 

[1] [2]  下一页

[]作者:宋井华  来源:快活林原创