把按钮的Tag属性设置0-N
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Tag_Button
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Buttons_Click(object sender,EventArgs e)
{
int Flag = int.Parse(((Button)sender).Tag.ToString());
switch (Flag)
{
case 0:
MessageBox.Show("This is the first button!");
break;
case 1:
MessageBox.Show("This is the second button!");
break;
case 2:
MessageBox.Show("This is the third button!");
break;
}
}
}
}