标签:
Application 类具有用于启动和停止应用程序和线程以及处理 Windows 消息的方法,如下所示:
Run 在当前线程上启动应用程序消息循环,并可以选择使某窗体可见。
Exit 或 ExitThread 停止消息循环。
DoEvents 在您的程序处于某个循环中时处理消息。
AddMessageFilter 向应用程序消息泵添加消息筛选器来监视 Windows 消息。
IMessageFilter 使您可以阻止引发某事件或在调用某事件处理程序前执行特殊操作。
该类具有用于获取或设置当前线程的区域性信息的 CurrentCulture 和 CurrentInputLanguage 属性。
不能创建此类的实例。
Application.EnableVisualStyles();//Enables visual styles for the application Application.SetCompatibleTextRenderingDefault(false);//If true, new controls that support UseCompatibleTextRendering use //the GDI+ based Graphics class for text rendering; //if false, new controls use the GDI based TextRenderer class;In Visual C# 2005 or later, //a call to SetCompatibleTextRenderingDefault is automatically generated in the Program.cs file. Application.Run(new mainFrm());
示例代码:
public class Form1 : Form { [STAThread] public static void Main() { // Start the application. Application.Run(new Form1()); } private Button button1; private ListBox listBox1; public Form1() { button1 = new Button(); button1.Left = 200; button1.Text = "Exit"; button1.Click += new EventHandler(button1_Click); listBox1 = new ListBox(); this.Controls.Add(button1); this.Controls.Add(listBox1); } private void button1_Click(object sender, System.EventArgs e) { int count = 1; // Check to see whether the user wants to exit the application. // If not, add a number to the list box. while (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo)==DialogResult.No) { listBox1.Items.Add(count); count += 1; } // The user wants to exit the application. // Close everything down. Application.Exit(); } }
标签:
原文地址:http://www.cnblogs.com/CandiceW/p/4445721.html