获取控件的实例我是谁

Sto*_*kid 1 c# instance visual-studio

有没有办法获得控件的实例谁是我的事件?

    private void TextBox1_TextChanged(object sender, EventArgs e)
    {
        TextBox1.Text = "hi";
        ThisControl.Text = "hi";
    }
Run Code Online (Sandbox Code Playgroud)

排序这样这两条线会做同样的事情吗?就像"This"关键字一样,但对于事件控件而不是类.

Ini*_*eer 5

object sender参数是对触发事件的控件的引用.因此,你可以做一些事情:

private void textBox1_TextChanged(object sender, EventArgs e)
{
     ((TextBox)sender).Text = "hi";

     // Or

     TextBox txtBox = sender as TextBox;
     txtBox.Text = "hi";
}
Run Code Online (Sandbox Code Playgroud)