Solved

Scroll Bar Buttons

Posted on 1999-01-21
10
227 Views
Last Modified: 2010-05-03
I'm creating an activex control which mimics the scroll bar buttons in the infamous outlook control.  I have the visual interface and basic properties down.  Just a couple of questions though...is there a simple api that can return the mouse button pressed?  And how can I simulate the behavior of scroll bar button when it is pressed and held down(i.e., continuous scroll in a given direction)?  The second question is the important one.

thanks, showme
0
Comment
Question by:showme
  • 4
  • 4
  • 2
10 Comments
 
LVL 1

Accepted Solution

by:
james_bligh earned 150 total points
ID: 1469949
Hi Showme,

I assume you are trying to respond to mouse clicks using the standard click event (if this is not the case, my apologies).

If this is the case then use the MouseDown event instead.  The MouseDown event interface gives some very useful info such as the button that was pressed and the (x,y) coordinates of the mouse at the time the button was pressed.

To do scrolling have the MouseDown event turn a boolean flag variable to true and capture the x and y coords in other global variables.

Next have the MouseMove event update the display every time the mouse moves over your control but only if the flag variable is set to true.  You can use the x and y coords you set when the button was pressed to calculate where the scrollbar should be moved to.

Lastly have the MouseUp event set the variable to false to stop the scrolling.

Hope this helps.

Rgds,

James
0
 
LVL 1

Expert Comment

by:Johnn
ID: 1469950
I'm just about done my ScrollWindow control...if you'd like a beta drop me a line.  All you do is drop this control on a container(form, picturebox, frame?, usercontrol) and the form adds V, H, or both scroll bars and scrolls the window in response to the users actions.

jnickle@shaw.wave.ca
0
 

Author Comment

by:showme
ID: 1469951
james_bligh,
I think I know what you mean but do you think you could provide some code to illustrate your answer.  Also, how can I specify the rate at which the VALUE property increases/decreases?  The way that I implemented your idea proved to approach the extremes too quickly?

thanks, showme
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:james_bligh
ID: 1469952
Showme,

Here's some sample code that creates a control that demonstrates what I was talking about earlier.  The reason that you were approaching the extremes too quickly could have been because you were not scaling the coords given by MouseMove to the actual min and max of your scrollbar (but that's just a guess :).

Note: I didn't realise it at the time of my first response but you may actually be able to do without the MouseDown and MouseUp events (and the mblnScrolling flag) altogether because the MouseMove event actually gives the button state as well.  It depends on what functionality you are trying to implement.

[Start Code]
Option Explicit
Private mintValue As Integer
Private mintMax As Integer
Private mintMin As Integer
Private mblnScrolling As Boolean

Private Sub UserControl_Initialize()
    mintValue = 0
    mintMax = 100
    mintMin = 0
    mblnScrolling = False
End Sub

Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        mblnScrolling = True
    End If
End Sub

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If mblnScrolling = True Then
        mintValue = (X / Width) * (mintMax - mintMin)
        If mintValue < mintMin Then
            mintValue = mintMin
        ElseIf mintValue > mintMax Then
            mintValue = mintMax
        End If
        UserControl_Paint
    End If
End Sub

Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        mblnScrolling = False
    End If
End Sub

Private Sub UserControl_Paint()
    Dim sngX As Single
    ' Blank the control
    Line (0, 0)-(Width, Height), RGB(255, 255, 255), BF
   
    ' Draw the marker line
    sngX = (mintValue / (mintMax - mintMin)) * Width
    Line (sngX, 0)-(sngX, Height), RGB(0, 0, 255)
End Sub
[End Code]

Hope this helps,

James
0
 
LVL 1

Expert Comment

by:Johnn
ID: 1469953
I think you guys would be saving yourselves alot of valuable time if you looked into my vbScrollWindow component.

http://members.home.net/wwwebsoft/vbScroll/index.htm

I understand you probably want to "know" how to do it, but in todays demanding market it's just sometimes better to use something that's already there instead of reinventing the wheel.

PS.  to correct a couple things in my earlier comment, frames can have a scroll bar but they don't seem to get scroll messages.  As for usercontrols, they don't provide a container property so it took some serious hacking but I finally got it work on usercontrols.  This new v2.0 will be available shortly.
0
 

Author Comment

by:showme
ID: 1469954
james_bligh,
Thank you for the code and I apologize for drawing this out any longer than necessary.  However, I may not have clear stated my needs.  You see, I have created a usercontrol with two buttons at each end to represent the scroll up and scroll down buttons.  There is nothing inbetween these two buttons.  The only way to change to value of the scroll bar control should result from either pressing the up button or down button and nothing else.  Therefore, I need a way to handle a case when the user presses, say, the down arrow button and holds down the mouse button.  The control should respond by internally increase the Value property, at a reasonable pace, until the Max is reached.  I hope that this clears up the problem, if not please let me know and I'll try to clarify it again.

thanks, showme
0
 
LVL 1

Expert Comment

by:james_bligh
ID: 1469955
Ahhhh

Now I understand :)

In that case use a timer control.

1) Use the MouseDown event to set a variable indicating which button was pushed - up or down then start the timer control (by setting enabled to true).

2) Have the Timer event for the timer control update the value after a suitable delay (set the interval property on the timer control to adjust this delay).  If the variable says go up increase the value if it says down go down.

3) Use the MouseUp event to disable the timer control (by setting enabled to false).

Phew...

Hope this works better for you Showme.

Rgds,

James



0
 

Author Comment

by:showme
ID: 1469956
james_bligh,
Regardless of how you answer this I'll award you the points.  I was hoping there might be another way to accomplish this task without the use of any other controls.  My own control is not made up of any constituent controls in an attempt to keep it's size small (buttons created via DrawFrameControl api).  I realize a timer control probably won't add that much but would appreciate any alternatives.

thanks, showme
0
 
LVL 1

Expert Comment

by:james_bligh
ID: 1469957
Showme,

There is an alternative:

1) Get rid of the timer control.

2) In the MouseDown event keep the variable to indicate up or down but instead of enabling the timer run a Subroutine to do the movement.

3) That routine should do a while loop while the variable is true.  That loop should update the value, call DoEvents and then call the Win32 API sleep for a number of milliseconds.

4) The MouseDown event should just set the scrolling variable bat to false.

The following code gives a very simple example of this with a project with a single form with a textbox called text1 that has a number in it.

[Start Code]
Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private mblnGo As Boolean

Private Sub Form_Load()
    mblnGo = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mblnGo = True
    RunGo
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mblnGo = False
End Sub

Private Sub RunGo()
    While mblnGo
        Text1.Text = Str(Val(Text1.Text) + 1)
        Sleep 100
        DoEvents
    Wend
End Sub
[End Code]

Rgds,

James
0
 

Author Comment

by:showme
ID: 1469958
james_bligh,
Fantastic!  I greatly appreciate all your help.

regards, showme
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Notepad++ how to remove delimiter : from beggning of the line? 3 114
Can we place a tooltip on the actual vb6 form 5 48
TT Auto Dashboard 13 95
vbModal 12 57
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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