Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Using key modifiers in NumericUpDown

$
0
0

VS 2012, VB, Windows Form

I have a NumericUpDown whose input I want to modify if - say - the Ctrl key is held down.  Specifically, I want it to change from +/- 1 to +/- 15.  This works fine if I click the up/down buttons but I also want it to work if use the up/down arrow keys.

The trouble is that the normal text behaviour of going to start/end kicks in.  Similarly, changing Ctrl to Shift makes it select, and Alt activates the mnemonic.

Is there any way round this?  I came across a reference to e.Handled but it isn't recognised the way I have it set up.  Maybe I need a tweak I'm not aware of, or perhaps I'm better off doing this another way.

Hope someone can help.

Regards,
Duncan

Private Sub numMinuteHandler(sender As NumericUpDown, e As EventArgs) Handles numMinute.Click, numMinute.GotFocus, numMinute.MouseWheel        

' Use Ctrl to step in 15 minute increments        

If (Control.ModifierKeys = Keys.Control) Then            

sender.Increment = 15            
sender.Maximum = 45 ' otherwise it will go to up 59 then down via 44, 29, 14        

Else            

' Revert to normal            
sender.Increment = 1            
sender.Maximum = 59        

End If        

sender.Select(0, Len(sender.Maximum))    

End Sub


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>