using System;
using System.Windows.Forms;
namespace CSharpUIFrameworkExample
{
public class Program
{
[STAThread]
static void Main()
{
// 创建一个应用程序实例
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 创建主窗口
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}
}
public class MainForm : Form
{
public MainForm()
{
// 设置窗口标题
this.Text = "C# UI Framework Example";
this.Size = new System.Drawing.Size(800, 600);
// 添加按钮控件
Button button = new Button();
button.Text = "Click Me";
button.Location = new System.Drawing.Point(350, 250);
button.Click += new EventHandler(Button_Click);
// 将按钮添加到窗体中
this.Controls.Add(button);
}
private void Button_Click(object sender, EventArgs e)
{
// 按钮点击事件处理
MessageBox.Show("Button clicked!");
}
}
}
这段代码展示了一个简单的C# WinForms应用程序,使用了System.Windows.Forms命名空间来创建用户界面。
Main方法中,我们初始化了Windows Forms应用程序,并启动了主窗口MainForm。MainForm构造函数中,设置了窗口的标题和大小,并添加了一个按钮控件。Button_Click,当用户点击按钮时会弹出一个消息框显示"Button clicked!"。这个例子展示了如何使用WinForms框架创建一个基本的用户界面。
上一篇:c# ref out
下一篇:c#矩阵运算
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站