NumericUpDown Mouse Wheel
-
Hallo, I am working with numericUpDown control in .net c#. The value of numericupdown changes on mouse wheel depending on number of spins mentioned in control panel->mouse->wheel. I want to overide this function such that value of numericupdown should not depend on control panel value.And always increment/decrement by value of 1.Irreespective of value mention at control panel, mouse wheel. I have used MouseWheel event numericUpDown1.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel); private void numericUpDown1_MouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { numericUpDown1.Value = numericUpDown1.Value + 1; } else if (e.Delta < 0) { numericUpDown1.Value = numericUpDown1.Value - 1; } } but this snippet instead of incrementing/decrement by 1, adds 1 to the number of spins mention in control panel, mouse wheel . Any kind of help will be appreciated.
-
Hallo, I am working with numericUpDown control in .net c#. The value of numericupdown changes on mouse wheel depending on number of spins mentioned in control panel->mouse->wheel. I want to overide this function such that value of numericupdown should not depend on control panel value.And always increment/decrement by value of 1.Irreespective of value mention at control panel, mouse wheel. I have used MouseWheel event numericUpDown1.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel); private void numericUpDown1_MouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { numericUpDown1.Value = numericUpDown1.Value + 1; } else if (e.Delta < 0) { numericUpDown1.Value = numericUpDown1.Value - 1; } } but this snippet instead of incrementing/decrement by 1, adds 1 to the number of spins mention in control panel, mouse wheel . Any kind of help will be appreciated.
Its because the numericUpDown's value gets changes by the mouse wheel, and then you handle the event for the mouss wheel and plus/minus 1 to the value. So your actually changing the value twice, if you see what i mean. What you need to do is something like this:
if (e.Delta > 0) {
numericUpDown1.Value -= e.Delta;
numericUpDown1.Value++;
}
else if (e.Delta < 0) {
numericUpDown1.Value += e.Delta;
numericUpDiwn1.Value--;
}That way you undo what the mouse wheel did, and then change the value yourself. EDIT:Never mind, that doesn't quite work, other way around, mouse event handled first, which may cause problems with minimum and maximum for the numreicUpDown. I'm not sure what you could do then. Even the ValueChanged event gets handled before the value has actually changed.
My current favourite word is: Bacon!
-SK Genius
modified on Thursday, April 24, 2008 9:47 AM
-
Its because the numericUpDown's value gets changes by the mouse wheel, and then you handle the event for the mouss wheel and plus/minus 1 to the value. So your actually changing the value twice, if you see what i mean. What you need to do is something like this:
if (e.Delta > 0) {
numericUpDown1.Value -= e.Delta;
numericUpDown1.Value++;
}
else if (e.Delta < 0) {
numericUpDown1.Value += e.Delta;
numericUpDiwn1.Value--;
}That way you undo what the mouse wheel did, and then change the value yourself. EDIT:Never mind, that doesn't quite work, other way around, mouse event handled first, which may cause problems with minimum and maximum for the numreicUpDown. I'm not sure what you could do then. Even the ValueChanged event gets handled before the value has actually changed.
My current favourite word is: Bacon!
-SK Genius
modified on Thursday, April 24, 2008 9:47 AM
Thanks for your effort and help :).
-
Hallo, I am working with numericUpDown control in .net c#. The value of numericupdown changes on mouse wheel depending on number of spins mentioned in control panel->mouse->wheel. I want to overide this function such that value of numericupdown should not depend on control panel value.And always increment/decrement by value of 1.Irreespective of value mention at control panel, mouse wheel. I have used MouseWheel event numericUpDown1.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel); private void numericUpDown1_MouseWheel(object sender, MouseEventArgs e) { if (e.Delta > 0) { numericUpDown1.Value = numericUpDown1.Value + 1; } else if (e.Delta < 0) { numericUpDown1.Value = numericUpDown1.Value - 1; } } but this snippet instead of incrementing/decrement by 1, adds 1 to the number of spins mention in control panel, mouse wheel . Any kind of help will be appreciated.