Visual C# 2010 Recipes A Problem-Solution Approach 代码2 —— Create a Windows-Based Application from the Command Line
2010-06-09 22:44
405 查看
Recipe01-02.cs
使用在命令行程序显示一个图形化操作界面,这个例子可以用在Windows Forms第一堂课上讲,让学员脱离IDE的依赖,彻底掌握Windows Forms编程核心概念,是个不错的范例。
using System; using System.Windows.Forms; namespace Apress.VisualCSharpRecipes.Chapter01 { class Recipe01_02 : Form { // Private members to hold references to the form's controls. private Label label1; private TextBox textBox1; private Button button1; // Constructor used to create an instance of the form and configure // the form's controls. public Recipe01_02() { // Instantiate the controls used on the form. this.label1 = new Label(); this.textBox1 = new TextBox(); this.button1 = new Button(); // Suspend the layout logic of the form while we configure and // position the controls. this.SuspendLayout(); // Configure label1, which displays the user prompt. this.label1.Location = new System.Drawing.Point(16, 36); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(148, 16); this.label1.TabIndex = 0; this.label1.Text = "Please enter your name:"; // Configure textBox1, which accepts the user input. this.textBox1.Location = new System.Drawing.Point(172, 32); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 1; this.textBox1.Text = ""; // Configure button1, which the user clicks to enter a name. this.button1.Location = new System.Drawing.Point(109, 80); this.button1.Name = "button1"; this.button1.TabIndex = 2; this.button1.Text = "Enter"; this.button1.Click += new System.EventHandler(this.button1_Click); // Configure WelcomeForm and add controls. this.ClientSize = new System.Drawing.Size(292, 126); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Controls.Add(this.label1); this.Name = "form1"; this.Text = "Visual C# 2010 Recipes"; // Resume the layout logic of the form now that all controls are // configured. this.ResumeLayout(false); } // Event handler called when the user clicks the Enter button on the // form. private void button1_Click(object sender, System.EventArgs e) { // Write debug message to the console. System.Console.WriteLine("User entered: " + textBox1.Text); // Display welcome as a message box. MessageBox.Show("Welcome to Visual C# 2010 Recipes, " + textBox1.Text, "Visual C# 2010 Recipes"); } // Application entry point, creates an instance of the form, and begins // running a standard message loop on the current thread. The message // loop feeds the application with input from the user as events. [STAThread] public static void Main() { Application.EnableVisualStyles(); Application.Run(new Recipe01_02()); } } }
使用在命令行程序显示一个图形化操作界面,这个例子可以用在Windows Forms第一堂课上讲,让学员脱离IDE的依赖,彻底掌握Windows Forms编程核心概念,是个不错的范例。
相关文章推荐
- Visual C# 2010 Recipes A Problem-Solution Approach 代码一 —— Create a Console Application from the Command Line
- Visual C# 2010 Recipes A Problem-Solution Approach 代码3—— 创建匿名类型
- Visual C# 2010 Recipes A Problem-Solution Approach 代码6——运算符重载
- Visual C# 2010 Recipes A Problem-Solution Approach 代码4——创建ExpandoObject Dynamic Type
- Visual C# 2010 Recipes A Problem-Solution Approach 代码4——自动完成属性
- Visual C# 2010 Recipes A Problem-Solution Approach 代码7——定义转换运算符
- Visual C# 2010 Recipes: A Problem-Solution Approach
- How to create Windows EventLog source from command line?
- Windows环境下利用“共享内存”实现进程间通信的C/C++代码---利用CreateFileMapping和MapViewOfFile
- John Paul Mueller, «Windows Administration at the Command Line for Windows 2003, Windows XP, and Windows 2000: In the Field Resu
- Create Command Line Tools
- command line subversion for windows
- delphi 2010 Cannot create file EditorLineEnds.ttr
- Excel 2010出现there was a problem sending the command to the program解决
- Create a new repository on the command line/Push an existing repository from the command line
- Create Windows Server 2008 cluster from the command line
- 在Python代码中调用windows command的方法
- 命令行管理远程windows.(Remote Command Line On Windows)
- 转载 Windows Command Line
- [转]Error: "SQL BPA command line has encountered a problem and needs to close"