The question now is: 1. How to make 81 a textbox Shared textchang events,
2. In the Shared textchange event occurs, how to say is textchang event name textbox,
CodePudding user response:
Control controls generated when busy assigned related event handlerSecondary processing method has two parameters, the first is the events of the control object, the second is the event related environmental parameters
CodePudding user response:
All the Control definition has the TextChanged eventpublic event EventHandler the TextChanged;you can register your own entrust
EventHandler proc=new EventHandler ((SDRS, arg)=& gt;
{
If (the SDR is a TextBox TXT & amp; & TXT. Tag!=null & amp; & TXT. Text==TXT. Tag. The ToString ())
{
TXT. Text=string. The Empty;
The Debug. WriteLine ($" I cleaned up the {TXT. Name} ");
}
});
The foreach (var c in yourControls)
C.T extChanged +=proc;
CodePudding user response:
Of course you can also writevar proc=new EventHandler ((SDRS, arg)=& gt;
{
If (the SDR is a TextBox TXT & amp; & TXT. Tag!=null & amp; & TXT. Text==TXT. Tag. The ToString ())
{
TXT. Text=string. The Empty;
The Debug. WriteLine ($" I cleaned up the {TXT. Name} ");
}
});
C in yourControls foreach (var. OfType())
C.T extChanged +=proc;
Use OfType<> Generics to filter control types, to avoid the TextBox type control register,
"Let 81 textbox sharing textchang events," the logic is wrong, event definitions on the specific object type (this is the Control), is a specific object instance (here the textbox instance) is triggered, there is no "sharing", this statement a delegate, which is a process, it can be registered for each Control, when the textbox the TextChanged event occurs, the event object independently, just used to call it a process, but the incoming call process parameters are different, the customer (caller) is also different, so there was not a "share the same event", is only Shared a method instance,