开发者

is there a way to identify the last control that was active in a .net windows forms code-behind?

I have a form where there is group of radio controls and some with textbox. If the cursor is on textbox and i try switching the cursor to a different radio button, i should be able to identify the last active control( in this case.. the textbox) and do some validation.

The LostFocus() event of textbox pops up message indicating that "this item should be filled in..". But if i want to go with a different radiobutton option in the same group, 开发者_如何转开发i dont want this message popping unnecessarily.

How do i avoid that?


The TextBox has Validating and Validated events-- you should use those instead of the LostFocus event. In the case of Validating, you can stop the user from leaving the TextBox if the criteria isn't correct. If you must use "something" like LostFocus, use the Leave event instead.

There is no "Last Active Control" type function. You would have to track that yourself by setting a variable on the Enter event of those controls.

That will lead to an ugly mess to maintain in my opinion. Validate at the form level is probably the best choice for the end user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜