Solved

Scrolling help

Posted on 2003-10-28
8
155 Views
Last Modified: 2010-05-03
I have an application that displays a map, but the map is too big, so there is a scroll bar on the botton to scroll left and right.  Is there a way I can assign Left and Right buttons to perform the same function as clicking on the arrows?


Thanks
0
Comment
Question by:sewoo
  • 4
8 Comments
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Try this:

Before using this, be sure to set the form's keypreview property to true.

--------------------------------------------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   
    If KeyCode = vbKeyLeft Then                                           'if left pressed
        If HScroll1.Value > 99 Then                                            'prevent the value to be negative
            HScroll1.Value = HScroll1.Value - 100                            'reduce the hscroll value
        End If
    End If
    If KeyCode = vbKeyRight Then                                         'if right pressed
        If HScroll1.Value < 10000 Then                                       'prevent the value to be to o big
            HScroll1.Value = HScroll1.Value + 100                           'enlarge the hscroll value
        End If
    End If
       
End Sub
-------------------------------------------------------------------------------------------------------

After that you should adjust the values in that code to fit your needs.


0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Maybe I misunderstood your question.
Maybe you were refering to mouse buttons.

if this is the case then use this

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    If Button = 1 Then
        If HScroll1.Value > 99 Then
            HScroll1.Value = HScroll1.Value - 100
        End If
    End If
    If Button = 2 Then
        If HScroll1.Value < 10000 Then
            HScroll1.Value = HScroll1.Value + 100
        End If
    End If

End Sub

Note that mouse doesnt have the repeat function when holding a button. so this code wil execute only once when clicked.
You can make it repeat by using timer(s). I'll try to do it also.
0
 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
This is the version with timers.

Create two timers, set their interval to 10 (or try what value gives the best bahaviour) and set their enabled property to false.   One timer is used to scroll left, and other to scroll right

Assign this code to timers and Forms mousedown and mouseup events accordingly.

Theory:
When mouse button is pressed, program checks which button is pressed, and according to the button number, activates the timer. Then the timer executes its code until the button is released.
When the button is released, program checks which it was, and deactivates the timer which was activated by that number

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then Timer1.Enabled = True
    If Button = 2 Then Timer2.Enabled = True
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then Timer1.Enabled = False
    If Button = 2 Then Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()                                     'scroll left
        If HScroll1.Value > 99 Then
            HScroll1.Value = HScroll1.Value - 100
        End If
End Sub

Private Sub Timer2_Timer()                                     'scroll right
        If HScroll1.Value < 10000 Then
            HScroll1.Value = HScroll1.Value + 100
        End If
End Sub
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 11

Expert Comment

by:dbrckovi
Comment Utility
Above code works but is still buggy.   When you press both buttons at the same time, picture shakes left and right.

Use this code to repair this:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        If Timer2.Enabled = True Then Timer2.Enabled = False: Exit Sub      'if another timer is already active then it means that another button is already pressed, and therefore deactivate it
        Timer1.Enabled = True
    End If
   
    If Button = 2 Then
        If Timer1.Enabled = True Then Timer1.Enabled = False: Exit Sub
        Timer2.Enabled = True
    End If
End Sub


Sorry that I used multiple comments to work throug this problem. It's becouse ideas came to me when I already posted a comment.
0
 

Author Comment

by:sewoo
Comment Utility
Thanks for the ideas, I'll give it a try tomorrow, but what I mean was the application has a command button called left and one called right, so I wanted to make it so that if I click on the button called "left" the screen scrolls left and if I click on "right" the screen scrolls right.
0
 

Accepted Solution

by:
PashaMod earned 0 total points
Comment Utility
PAQed, with points refunded (250)

PashaMod
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now