[当我在VB.Net“ NumericUpAndDown”中滚动鼠标滚轮时,它滚动值的3倍,我只想滚动1次...
经过一番搜索,我发现了这个
Public Sub RolagemMouse(sender As Object, e As MouseEventArgs)
' Periocidade.MouseWheel, Parcelas_UP_DWN.MouseWheel, TB_Valor.MouseWheel
Try
If e.Delta > 0 Then
sender.Value += sender.increment
Else
sender.Value -= sender.increment
End If
Catch
End Try
CType(e, HandledMouseEventArgs).Handled = True
End Sub
它解决了我的问题,但是我的表单中有很多NumericUpAndDown,然后在添加的FormLoad事件中我有了另一个主意
For Each grupo As GroupBox In Controls.OfType(Of GroupBox)
For Each objeto As NumericUpDown In grupo.Controls.OfType(Of NumericUpDown)
AddHandler objeto.MouseWheel, AddressOf RolagemMouse
Next
Next
但是那是不切实际的,我必须以各种形式来表示,还有更好的方法吗?
这是一个继承自NumericUpDown的简单自定义控件,该控件重写OnMouseWheel
以应用定义的Increment
值,而不是由SystemInformation.MouseWheelScrollLines
类应用的默认SystemInformation.MouseWheelScrollLines
(通常为=3
)。
[请注意,您的代码当前添加到Value的增量中,没有计算UpDownBase和Minimum
属性,因此,由于[C0 ]有时会超出可接受的范围。
Maximum
存在是有原因的,即使它看起来是空的也是如此。如果您决定使用它,请不要切断它。在Visual Studio中,可以使用“搜索和替换”功能将所有现有的NumericUpdown控件替换为自定义控件(除非重新定义,否则可以使用Control + H进行invoked)。
Value