none
Need mousewheel functionaly on winform using upand down arrow key RRS feed

  • Question

  • Hello,
    I have win form in vb .net and it has one combo placed on it which get focus as soon as form loads, If I move mousewheel then its correctly move my panel but if I click anywhere on form and try to go up and down using up and down arrow then it moves data in combo but won't scroll the whole form like i do using mousewheel.

    I need solution for this as early as possible , Please help.

    Thanks in advance.

    Regards,
    Nupur D
    Friday, February 21, 2020 4:42 PM

Answers

  • Hello Xingyu,

    Thanks for your reply and your code works with button click but we don't want any other added control to handle this.

    Finally i got one code which worked for me along with some part of your code

     Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
            If (keyData = Keys.Up) Then
                ScrollValue -= Panel1.VerticalScroll.LargeChange
                Return True
            End If
            If (keyData = Keys.Down) Then
                ScrollValue += Panel1.VerticalScroll.LargeChange
                Return True
            End If
            Return MyBase.ProcessCmdKey(msg, keyData)
        End Function

    Public sValue As Integer = 0
        Property ScrollValue As Integer
            Get
                Return sValue
            End Get
            Set(ByVal value As Integer)
                sValue = value

                If ScrollValue < Panel1.VerticalScroll.Minimum Then
                    sValue = Panel1.VerticalScroll.Minimum
                End If

                If ScrollValue > Panel1.VerticalScroll.Maximum Then
                    sValue = Panel1.VerticalScroll.Maximum
                End If
                Panel1.VerticalScroll.Value = sValue
                Panel1.PerformLayout()
            End Set
        End Property

    Thanks & Regards,

    Nupur D




    • Marked as answer by nupurd Tuesday, February 25, 2020 6:17 PM
    • Edited by nupurd Tuesday, February 25, 2020 6:18 PM
    Tuesday, February 25, 2020 5:32 PM

All replies

  • Hi

    That does not seem to be default behaviour.If I am correct, yjen presumably you have code to do it, please post the code.


    Regards Les, Livingston, Scotland

    Friday, February 21, 2020 5:07 PM
  • Hi nupurd,

    Thank you for posting here.

    According to your description, I find a reference about how to correctly scroll panel using mousewheel event.

    How can I scroll my panel using my mousewheel?

    The code in the reference is c#, and you need to convert it to vb.

    Besides, if I have any misunderstanding, please provide some related code here. It will help us to analyze your problem and make a test.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 24, 2020 6:13 AM
    Moderator
  • Hello Xingyu,

    Thanks for your reply,

    But my problem is not related to mouse wheel move its working on my panel but I want to use up and down arrow to move my panel up and down which is not happening.

    When I use up and down arrow after setting focus on panel also it moves combo data which never lost focus until i tab it.

    I need up and down arrow to move my panel like i do using mouse wheel if i have focus anywhere on form.

    Thanks & Regards,

    Nupur Deshmukh

    Monday, February 24, 2020 10:08 AM
  • Hi nupurd,

    Thanks for your feedback.

    I make a test based on your description, and hope the following code can help you.

        Private Sub Up_Click(sender As Object, e As EventArgs) Handles Up.Click
            ScrollValue -= Panel1.VerticalScroll.LargeChange
        End Sub
    
        Private Sub Down_Click(sender As Object, e As EventArgs) Handles Down.Click
            ScrollValue += Panel1.VerticalScroll.LargeChange
        End Sub
    
        Public sValue As Integer = 0
        Property ScrollValue As Integer
            Get
                Return sValue
            End Get
            Set(ByVal value As Integer)
                sValue = value
    
                If ScrollValue < Panel1.VerticalScroll.Minimum Then
                    sValue = Panel1.VerticalScroll.Minimum
                End If
    
                If ScrollValue > Panel1.VerticalScroll.Maximum Then
                    sValue = Panel1.VerticalScroll.Maximum
                End If
                Panel1.VerticalScroll.Value = sValue
                Panel1.PerformLayout()
            End Set
        End Property

    Besides, here's a reference you can refer to, and you can convert the C# code to VB.

    How to Programmatically Scroll a Panel

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 25, 2020 10:12 AM
    Moderator
  • Hello Xingyu,

    Thanks for your reply and your code works with button click but we don't want any other added control to handle this.

    Finally i got one code which worked for me along with some part of your code

     Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
            If (keyData = Keys.Up) Then
                ScrollValue -= Panel1.VerticalScroll.LargeChange
                Return True
            End If
            If (keyData = Keys.Down) Then
                ScrollValue += Panel1.VerticalScroll.LargeChange
                Return True
            End If
            Return MyBase.ProcessCmdKey(msg, keyData)
        End Function

    Public sValue As Integer = 0
        Property ScrollValue As Integer
            Get
                Return sValue
            End Get
            Set(ByVal value As Integer)
                sValue = value

                If ScrollValue < Panel1.VerticalScroll.Minimum Then
                    sValue = Panel1.VerticalScroll.Minimum
                End If

                If ScrollValue > Panel1.VerticalScroll.Maximum Then
                    sValue = Panel1.VerticalScroll.Maximum
                End If
                Panel1.VerticalScroll.Value = sValue
                Panel1.PerformLayout()
            End Set
        End Property

    Thanks & Regards,

    Nupur D




    • Marked as answer by nupurd Tuesday, February 25, 2020 6:17 PM
    • Edited by nupurd Tuesday, February 25, 2020 6:18 PM
    Tuesday, February 25, 2020 5:32 PM