C#/.NET 抽象文本框click事件
View Code1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace WindowsFormsApplication111 {12 public partial class Form2 : Form13 {14 public Form2()15 {16 InitializeComponent();17 foreach (var item in this.Controls)18 {19 TextBox tbox = (TextBox)item;20 if (tbox != null)21 {22 tbox.Click += new EventHandler(eventText);23 }24 }25 }26 27 void eventText(object sender, EventArgs e)28 {29 TextBox tbox = (TextBox)sender;30 MessageBox.Show(tbox.Name);31 }32 }33 }
TAG: