首页 > 代码库 > C#之winform基础 button1_Click(object sender, EventArgs e)中sender是啥及其用法

C#之winform基础 button1_Click(object sender, EventArgs e)中sender是啥及其用法

1、UI

技术分享

 

 

2、代码

 1 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.Threading.Tasks; 9 using System.Windows.Forms;10 11 namespace WindowsFormsApplication112 {13     public partial class Form1 : Form14     {15         public Form1()16         {17             InitializeComponent();18         }19 20         private void button1_Click(object sender, EventArgs e)21         {22             //sender object类型,里面装的是button1,这就是关键一点了。23             Button btn = (Button)sender;24             textBox1.Text = btn.Text;25         }26 27         private void button2_Click(object sender, EventArgs e)28         {29             //这个sender里面装的是button230             button1_Click(sender, e);31         }32     }33 }

 

 

 

3、效果

技术分享

 

技术分享

 

C#之winform基础 button1_Click(object sender, EventArgs e)中sender是啥及其用法