How to do an event in more than one box/button/label at the same time?

Asked

Viewed 18 times

0

On Vb.net I used a command that was:

private sub txt1_LostFocus(object sender, EventArgs e) handles txt2.text, txt3.text
    sender.text = Ucase(sender.text)
end sub

This caused all text boxes to be in Uper case as soon as it lost focus. I want to perform the same type of action in C# without having to program a Leave for each text box, as I can do?

1 answer

1


Events are recorded in the class NomeDoForm.Designer.cs, for example if the form is called Form1, it has a file "Form1.Cs" and there will be the "Form1.Designer.Cs".

If you open this class, you will see that the event is registered there, something like this based on the names you have in your question:

this.txt2.LostFocus+= new System.EventHandler(this.txt1_LostFocus);

Just then log the same event to want other similar controls (the method signature may vary between a Button or Textbox):

this.txt2.LostFocus+= new System.EventHandler(this.txt1_LostFocus);
this.txt3.LostFocus+= new System.EventHandler(this.txt1_LostFocus);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.