How do I activate mouse's scrollwheel
I have a project that can display a lot of data in a form. The form has a scrollbar on one side and I can click on the scrollbar and move up or down in the data.
My question: How can I activate my mouse's scrollwheel so that I can roll the scroll wheel and move up or down in the data?
Thanks in advance to those who offer assistance!!
Re: How do I activate mouse's scrollwheel
Try the first post in this thread, but substitute the scroll bar's hwnd for Me.hwnd in the FormLoad sub.
Re: How do I activate mouse's scrollwheel
take a look at the mousewheel link in my sig.
Re: How do I activate mouse's scrollwheel
al42 and bushmobile,
Thanks for your replies! I'll give the suggestion a shot and see what comes up!
I'll let you know as soon as possible if it does the trick for me.
Re: How do I activate mouse's scrollwheel
al42 and bushmobile,
I tried your suggestions, but they did not work. I ended up downloaded a file from Microsoft's site that installed Microsoft Intelliware 4.12 and that did the trick for me.
I appreciate your offers of help.....keep up the good work!
Thanks! :thumb:
Re: How do I activate mouse's scrollwheel
You can do it with the code i linked to - you'd have to modify it though.
Bear in mind that if you give your app to anyone else it might not work for them. if it's just for you then updating the driver is ok - if it's for other people then you'll have to handle the messages yourself.
Re: How do I activate mouse's scrollwheel
bushmobile,
I'm thinking perhaps I didn't modify your code correctly. Can you tell me where I'd modify the code, if my form was named "ThisIsJustATest", and the field I am interested in is "FieldThisIsAField" ??
Would I have to put the "CallWheelHook" into every field, or just at the beginning of a form?
Thanks in advance! I appreciate your help.
Re: How do I activate mouse's scrollwheel
bushmobile,
Are you there????
Re: How do I activate mouse's scrollwheel
sorry, i haven't got VB on this computer and can't get access to the code.
From memory it should be something like this:
VB Code:
' On the Form:
Private Sub MouseWheel(...Parameters...)
'
' code
Select Case blah
' Leave the
' Case TypeOf ctl Is TextBox.... one
' and the Case Else one - get rid of the others
End Select
' Where it has
Me.Caption = IIf(... 'or something
' either decrease or increase the VScrollBars value according the value of rotation
End Sub
If you post the sub i mentioned above I should be able to help you out more.
1 Attachment(s)
Re: How do I activate mouse's scrollwheel
finally got VB back - here's an example (it's not brilliant but it should point you in the right direction)
Re: How do I activate mouse's scrollwheel
Hi BushMobile,
Great piece of code/example. However I think I found a bug.
The error is
Code:
Runtime Error 91
Object variable or with block variable not set
The steps to generate the error are:
1) Place a textbox inside a picturebox.
2) click inside the textbox and rotate the wheel. (Which is obviously ignored by your MouseWheel event.) (everything is still fine)
2) move the mouse outside the bounds of the textbox (in my case pointer is now over picturebox) but DO NOT click the mouse.
3) Error is generated when you roll the mousewheel over the picturebox.
I suspect your routine thinks it's still over the textbox, and has to do with VB not detecting when the mouse leaves the bounds of a control too well?
Regards,
Nap
PS.. Wish I could fix it for you, but I'm not that skilled with API code. But would love it if you found the answer ASAP. :bigyello:
Re: How do I activate mouse's scrollwheel
Hi BushMobile,
I have been able to eliminate the error from occuring some of the time by:
Code:
picturebox_mousemove (....)
picturebox.setfocus
end sub
But the error still occurs when there is a small gap between textboxes and you happen to be scrolling while the mouse moves over the gap. As I said b4, VB isn't good at detecting when the mouse moves off the control.
Cheers,
Nap
Re: How do I activate mouse's scrollwheel
have a look at posts #14 - #17 in the codebank thread - that'll fix the error.
but the textbox will only scroll if it has focus - so i'm just going to see if can do something to fix that.
Re: How do I activate mouse's scrollwheel
Understand about the texbox. The error happens when you give the textbox focus and then move off it without clicking the mouse over the next control it's hovering over.
everything is working, except when there is a transition of the mouse over controls. If you move too quick and rotate the wheel while you're doing it, the error is generated.
I will look at posts 14 - 17 now.
Thanks & Cheers,
Nap
Re: How do I activate mouse's scrollwheel
and the fix is:
VB Code:
Public Sub MouseWheel(ByVal MouseKeys As Long, ByVal Rotation As Long, ByVal Xpos As Long, ByVal Ypos As Long)
Dim ctl As Control, cContainerCtl As Control
Dim bHandled As Boolean
Dim bOver As Boolean
For Each ctl In Controls
'
'
' change this case
Case TypeOf ctl Is PictureBox, TypeOf ctl Is Frame
Set cContainerCtl = ctl: bHandled = False
'
'
Next ctl
If Not cContainerCtl Is Nothing Then
If TypeOf cContainerCtl Is PictureBox Then PictureBoxZoom cContainerCtl, MouseKeys, Rotation, Xpos, Ypos
Else
' Scroll was not handled by any controls, so treat as a general message send to the form
Me.Caption = "Form Scroll " & IIf(Rotation < 0, "Down", "Up")
End If
End Sub
only change the PictureBox case in the sub, keep the rest of the loop the same.
Re: How do I activate mouse's scrollwheel
nope, still getting the same error.
Try to move the mouse off the textbox while rolling the wheel at the same time.
I don't know if it's significant or not, but I'm not using a frame in my code. Just a textbox inside a picturebox.
Cheers,
Nap
Re: How do I activate mouse's scrollwheel
have a look at the CodeBank thread, I've just added a Nested Controls example
Re: How do I activate mouse's scrollwheel
After I changed the code to use the GetAncestor API, it worked. As per Post 15.
Thank you very much.
Cheers,
Nap
Re: How do I activate mouse's scrollwheel
yes - the previous fix i mentioned was in addition to the use of GetAncestor, I probably didn't make that clear...