How to keep a form from scrolling?

M

Max Moor

Hi All,
I'm using my mousewheel to scroll a listbox on my form. The best way
I've found is to use the MouseWheel event to set the focus to the listbox.
It works fine, but if the focus is on any other control on the form, it
scrolls the information in the current record out (all the controls go
blank). I know I can stop this by setting AllowAdditions to No, but I need
it to be yes for the sake of some of the other code I have.

Is there a way to trap the current record on the form scrolling out
of view, and either stopping the scroll or scrolling it back?
 
M

Max Moor

Stephen Lebans has code to disable the mouse wheel at:
www.lebans.com

Hi Allen,
I thought about using that, but really wanted to be able to scroll
part of the form. I hoped for a better solution, but ended up building
the MouseWheel code in "ACC2000: How to Detect and Prevent the Mouse
Wheel from Scrolling Through Records in a Form".

Then I added the code:

Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel

Private Sub Form_Load()
Set clsMouseWheel = New MouseWheel.CMouseWheel
Set clsMouseWheel.Form = Me
clsMouseWheel.SubClassHookForm
End Sub

Private Sub Form_Close()
clsMouseWheel.SubClassUnHookForm
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
End Sub

Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)

Dim ctlCurrent As Control

Set ctlCurrent = Screen.ActiveControl
If (ctlCurrent.Name <> "lstMyListbox") Then

Me!lstMyListbox.SetFocus
Cancel = True

End If
End Sub

When the wheel moves, I set the focus to the part of the form I
want to scroll, if it isn't there already, and cancel the event. It
seems to work pretty well. Now that it's done, and turned out to be
much easier than I thought, I'm just as happy with it.

Anyway, thanks for the pointer - Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top