Sign in to follow this  

[.net] NumericUpDown and focus questions ...

This topic is 3319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, To keep things simple, I have a NumericUpDown in my form which has the focus. When I click anywhere else on the form, I want to hide this NumericUpDown. So, I added a new EventHandler to the LostFocus property of my control. It works almost fine : when I click outside the NumericUpDown, the control is hidden. But the problem is that when I click on an arrow to edit the value of the NumericUpDown, it also gets hidden ! For a reason I ignore, LostFocus is fired when I click on the up or down arrow of the NumericUpDown ... is this the standard behavior ? And if so, how should I do to only hide the control when clicking outside of it, but not when editing it ?

Share this post


Link to post
Share on other sites
a better way would be to handle mouse click events on the rest of the controls or the main form itself

If you do that you can safely know that you are ready to hide your control

Share this post


Link to post
Share on other sites
Hi,
managed C++, but it's the same as C#.

@Evilnando: My main form has a lot of other component ... I would have to catch click events for all those component and call a delegate to hide my NumericUpDown ... which is not really an option I want to consider :) And each time I add a new component, be it a simple Label, I'd have to write code to catch click event, include the header of the class handling the NumericUpDown, and register the correct delegate ... a nightmare.

Any other idea ?

Share this post


Link to post
Share on other sites
the only other option you really have is to create a custom control by yourself that mimics the num_updwn behavior

that way you have more control on how to manage focus events

Share this post


Link to post
Share on other sites
Ok, I was probably too tired yesterday, I've found the solution : the ContainsFocus property. It's true if the control or any of its children has focus. So in my LostFocus callback, I simply have to check this property, and hide the NumericUpDown only when it's false.

The strange thing though is that before that, I tried to check the Focused property of all the NumericUpDown controls and it didn't work ... But anyway, this property works really fine.

Share this post


Link to post
Share on other sites

This topic is 3319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this