Identify which textbox has fired a text changed event

后端 未结 3 1131
鱼传尺愫
鱼传尺愫 2021-01-19 05:19

I have a number of text boxes that are dynamically created via code.

I would like to be able to assign a generic event handler to all the textboxes for the text cha

3条回答
  •  遇见更好的自我
    2021-01-19 05:40

    Cast object sender(your textbox which fired event) to TextBox.

    If only one property is what you want then write

    string propertyName = ((TextBox)sender).Name; 
    

    But when more than one property is required, then it is better to create a Textbox variable and use it like.

    TextBox txtbox =  (TextBox)sender;
    

    Then you can use any property of it like

    string propertyName = txtbox.Name; 
    
    MessageBox.Show(proptertyName);
    MessageBox.Show(txtbox.Content.ToString());
    

提交回复
热议问题