利用按钮的Tag属性触发其事件

来源:互联网 发布:linux piwik安装详解 编辑:程序博客网 时间:2024/04/26 14:02

把按钮的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;            }        }    }}


 

原创粉丝点击