Closed Bahaa-Sobhy closed 7 years ago
By calling e.Cancel = true
, you're ceasing the event propagation that allows the control to lose focus. Each control has its own associated event, so handling an event in one control has no effect on the other controls. In your case it seems you should just set the colors to indicate invalid data and don't touch e
.
Also, take a look at the event propagation chain. Validated
follows Validating
. So you're setting one color and then immediately setting another.
Thanks m66n... I removed one of them, but in vain...
Thanks anyway :)
It has nothing to do with the number of controls. Try doing something similar with a set of TextBox
s and you'll see the same behavior. You're cancelling an event when you shouldn't. And you should do all of your coloring in Validating
or Validated
, but not in both.
hello m66n,
First I would like to thank you for this great work... But at the practical scenario, when you add many IPAddressControl Controls (ex. for IP, subnet mask, default gateway... etc) , it causes confusion to the events (Validating and Validated) they hang to the first control and don't work for the second, third, fourth... Controls.
for example:
Whatever is the action to take inside these two events, the second and third controls (in the given example Subnet and Gateway) they don't do the required actions, instead only the BackColor of the first control (IPv4) is changed, moreover the application can't be closed by any mean!
When I tried to remove "e.Cancel = true;" nothing changes in the Controls problem, but the Applicatopn can be closed normally.
What do you think the reason of this problem? I think it's something related to Disposing the Control event when it's done... Any idea/solution would be highly appreciated.
Thanks in advance.