NumericUpDown
NumericUpDown
NumericUpDown
NumericUpDown
NumericUpDown
NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown
NumericUpDown NumericUpDown
NumericUpDown
Go Back  Xtreme Visual Basic Talk > > > NumericUpDown


Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2016, 10:22 AM
Roger-U Roger-U is offline
Centurion
 
Join Date: Apr 2008
Location: Surrey, UK
Posts: 112
Default NumericUpDown


When using the mousewheel on these it always changes by 3 .. there is no way to set the mousewheel increment .. and apparently it won't be fixed in VS2008 ... don't know about the later versions.

Anyway there are various suggestion about overriding WinProc to eat the mousewheel event ... but

it appears the increment IS only 1 but its valueChanged event is called 3 times in very quick succession ... so an easy fix is

Code:
  Private Sub num_ValueChanged(ByVal sender As Object, _
               ByVal e As System.EventArgs) Handles numScale.ValueChanged
    Dim i%
    Static t, n As Integer, ih As Boolean

    If ih Then Exit Sub
    ih = True

    i = System.Environment.TickCount
    If i < t + 2 Then numScale.Value = n
    t = i
    n = numScale.Value

    ih = False

  End Sub
Reply With Quote
  #2  
Old 04-28-2016, 11:21 AM
PlausiblyDamp's Avatar
PlausiblyDampNumericUpDown PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you are doing this a lot it might be easier to create a control that inherits from NumericUpDown and override the OnMouseWheel method rather than handling the ValueChanged function.

Overriding OnMouseWheel would also prevent you having to handle changes from the up / down buttons or a user typing into the textbox.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 04-28-2016, 10:45 PM
Cerian Knight's Avatar
Cerian KnightNumericUpDown Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,199
Default

Quote:
Originally Posted by Roger-U View Post
When using the mousewheel on these it always changes by 3
Granted, your method seems to work fine, but no, '3' is only the 'default'. It can be changed manually in Control Panel/Mouse Properties/Wheel, either by changing the line increment to the specific value you need (e.g. to '1', like I did), or by changing to Screen mode (which has the effect of '1' on the NumericUpDown).

If you really wanted to, you could change that value programmatically (with SPI)... but other less invasive programmatic solutions (as were discussed) might still benefit from interrogating the current value (also with SPI).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 04-28-2016 at 10:52 PM.
Reply With Quote
  #4  
Old 04-29-2016, 04:30 PM
Roger-U Roger-U is offline
Centurion
 
Join Date: Apr 2008
Location: Surrey, UK
Posts: 112
Default

yes maybe 3 is just what happens to be on my computer - but whatever number the fact remains that Windows achieves this by rapidly changing it by 1 several times.. and my method very simply limits the change to 1 over a couple of system ticks - one could increase that to say 20 and it still would not affect any human use of the control.

Using SPI would work, but we don't want to changes the user's preference for other programs.

My idea is simple, and easy to follow ... one usually scores points for that ... and I posted this because when I looked for solutions all the ones I found suggested overriding Winproc - which has its uses, but is not necessary here, in fact it does not work as when the NumericUpDown control has the focus it seems to trap the message &H20A and it never gets to Winproc at all

Simple is best if it does the job ... and this is not rocket science... (and yes I have worked on real rocket science projects too)
Reply With Quote
Reply

Tags
mousewheel, increment, event, numscale.value, object, byval, fix, system.eventargs, sender, private, num_valuechangedbyval, easy, integer, true, false, exit, boolean, dim, numscale.valuechanged, static, succession, handles, apparently, set, vs2008


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
NumericUpDown
NumericUpDown
NumericUpDown NumericUpDown
NumericUpDown
NumericUpDown
NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown NumericUpDown
NumericUpDown
NumericUpDown
 
NumericUpDown
NumericUpDown
 
-->