基础1
using System.Windows.Forms;
public class MyWindow : Form // 继承Form类,表示这是个窗口
{
public MyWindow()
{
this.Text = "我的第一个窗口"; // 窗口标题
this.Size = new System.Drawing.Size(300, 200); // 窗口大小
}
// 程序入口
static void Main()
{
Application.Run(new MyWindow()); // 启动窗口!
}
}
基础2
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyWindow : Form
{
// 输入框和按钮声明(方便全局访问)
private TextBox myInput;
private Button myButton;
public MyWindow()
{
// 窗口设置
this.Text = "读纸条小工具";
this.Size = new Size(300, 200);
// 创建输入框
myInput = new TextBox();
myInput.Location = new Point(50, 30);
myInput.Size = new Size(150, 30);
this.Controls.Add(myInput);
// 创建按钮
myButton = new Button();
myButton.Text = "点我读纸条";
myButton.Location = new Point(50, 80);
myButton.Size = new Size(150, 40);
this.Controls.Add(myButton);
// 绑定按钮点击事件
myButton.Click += (sender, e) =>
{
// 获取输入框文字
string text = myInput.Text;
// 显示结果
MessageBox.Show("你写的是:" + text);
};
}
[STAThread]
static void Main()
{
Application.Run(new MyWindow()); // 启动!
}
}
2773

被折叠的 条评论
为什么被折叠?



