Jump to content
  • Advertisement
Sign in to follow this  
paic

[.net] NumericUpDown and focus questions ...

This topic is 3628 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!