using System;
using System.Windows.Forms;
namespace CSharpControlsExample
{
public class ExampleForm : Form
{
public ExampleForm()
{
// 创建一个按钮控件
Button button = new Button
{
Text = "点击我",
Location = new System.Drawing.Point(50, 50)
};
// 添加按钮点击事件处理程序
button.Click += (sender, e) =>
{
MessageBox.Show("你点击了按钮!");
};
// 创建一个文本框控件
TextBox textBox = new TextBox
{
Location = new System.Drawing.Point(50, 100),
Width = 200
};
// 创建一个标签控件
Label label = new Label
{
Text = "请输入内容:",
Location = new System.Drawing.Point(50, 80)
};
// 将控件添加到窗体中
this.Controls.Add(button);
this.Controls.Add(textBox);
this.Controls.Add(label);
// 设置窗体属性
this.Text = "C# 控件示例";
this.Size = new System.Drawing.Size(300, 200);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ExampleForm());
}
}
}
Button 控件:
TextBox 控件:
Label 控件:
窗体设置:
this.Controls.Add
方法将各个控件添加到窗体中。主程序入口:
Application.Run
方法启动应用程序并显示窗体。下一篇:c# textbox
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站