12-6.cs

来自「这是学习java基础的好的源代码的学习资料」· CS 代码 · 共 45 行

CS
45
字号
//程序12-6
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

public class TheForm : Form 
{  
	private TextBox textbox;
	private Button button;
	private Label label;
   
	public TheForm() : base() 
	{  
		textbox = new TextBox();
		textbox.Size = new Size(100,100);
		textbox.Location = new Point(150,50);
		textbox.Text = " ";
      
		button = new Button();
		button.Location = new Point(50,100);
		button.Text = "演示";

		label=new Label();
		label.Location=new Point(50,50);
		label.Size=new Size(150,100);
		label.Text="演示事件";
     
		button.Click += new EventHandler(this.Button_Clicked); //创建委托并添加到事件
		Controls.Add(textbox);
		Controls.Add(button);   
		Controls.Add(label);
	}
	
	private void Button_Clicked(object sender, EventArgs e) //事件处理程序.
	{
		textbox.Text = "事件响应了!";
	}
	
	public static void Main(string[] args) 
	{
		Application.Run(new TheForm());
	}  
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?