文章

C#的Sender是干什么的

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) //Sender就是这么用的,它是消息的发送者/拥有者
        {
            if (sender == this.button1)
            {
                textBox1.Text = "按钮1被点击";
            }
            if (sender == this.button2)

            {
                this.textBox1.Text = "按钮2被点击";
            }
        }
    }
}

原文来自:C#的Sender是干什么的,尊重自己,尊重每一个人;转发请注明来源!
0 0

发表评论