Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

Need to slow down a mouse wheel, witch is changing tabs in a TabControl.

Hi,

This code work fine, but just a little bit to fast, what would be the right way to slow down the speed?

    Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
        If CBool(Control.ModifierKeys And Keys.Shift) Then
            If e.Delta > 0 Then
                'Up
                If TabControl1.SelectedIndex < 9 Then
                    TabControl1.SelectedIndex = TabControl1.SelectedIndex + 1
                End If
            Else
                'Down
                If TabControl1.SelectedIndex > 0 Then
                    TabControl1.SelectedIndex = TabControl1.SelectedIndex - 1
                End If
            End If
        End If
    End Sub

Open in new window



Any help will be greatly appreciated

Best regards
NaanPLS
0
NaanPLS
Asked:
NaanPLS
2 Solutions
 
Jaime OlivaresSoftware ArchitectCommented:
I had this problem before. You are performing an action for any wheel turn, no matters how much.
Your first approach would be to perform an action just when the delta is greater than some value, but this would work just when you perform a fast turn.
A better approach is to accumulate the deltas until they surpasses some threshold value. Something like (not tested):

Private accumDelta as Integer  'Declare this field somewhere
Private Const deltaThreshold as Integer = 10

Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
    If CBool(Control.ModifierKeys And Keys.Shift) Then
        If (e.Delta > 0 And accumDelta > 0) Or (e.Delta < 0 And accumDelta < 0) Then
              accumDelta = accumDelta + e.Delta
        Else
              accumDelta = e.Delta
        EndIf
        If accumDelta > deltaThreshold  Then
             If TabControl1.SelectedIndex < 9 Then
                 TabControl1.SelectedIndex = TabControl1.SelectedIndex + 1
             End If
             accumDelta = accumDelta - deltaThreshold
        EndIf
        If accumDelta < -deltaThreshold  Then
             If TabControl1.SelectedIndex > 0 Then
                 TabControl1.SelectedIndex = TabControl1.SelectedIndex - 1
             End If
             accumDelta = accumDelta +  deltaThreshold
        EndIf
    End If
End Sub

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
According to the docs, you should act on a delta greater than 120:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousewheel.aspx

    "The UI should scroll when the accumulated delta is plus or minus 120."
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now