111,130
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Windows.Forms;
class Form1 : Form
{
Form1()
{
Button btnA = new Button();
btnA.Parent = this;
btnA.Text = "按钮&A";
btnA.Tag = "这是按钮A!";
btnA.Click += new EventHandler(ButtonClick);
Button btnB = new Button();
btnB.Parent = this;
btnB.Text = "按钮&B";
btnB.Top = 30;
btnB.Tag = "This is Button B";
btnB.Click += new EventHandler(ButtonClick);
}
void ButtonClick(object sender, EventArgs e)
{
// 这就是你要的:
string tag = (sender as Control).Tag.ToString();
MessageBox.Show(tag);
}
static void Main()
{
Application.Run(new Form1());
}
}