[RESOLVED] MouseWheel scroll inside Rich Text Box with scrollbars disabled
Ok so i have this Rich Text Box with disabled scroll bars. I've added a module to "catch" Mouse Wheel events. In order to scroll up/down inside the control i added the following code in Form_Load:
Code:
'Mouse Wheel Rotated Up
If Count > 0 Then
SendKeys "{UP}"
'Mouse Wheel Rotated Down
Else
SendKeys "{DOWN}"
End If
Simple, but it doesn't work :( Error: Premission Denied in SendKeys. Why is this happening ? Thanks.
Re: MouseWheel scroll inside Rich Text Box with scrollbars disabled
Got it to work with WScript.Shell SendKeys replacement.
Code:
Set WshShell = CreateObject("WScript.Shell")
If Me.ActiveControl = Me.RTFTextBox Then
If Rotation > 0 Then
WshShell.SendKeys "{UP}"
Else
WshShell.SendKeys "{DOWN}"
End If
End If
Re: [RESOLVED] MouseWheel scroll inside Rich Text Box with scrollbars disabled
this http://www.vbforums.com/showthread.p...-someting-else came up a couple of weeks ago.
Good to see you got it sorted.
Re: [RESOLVED] MouseWheel scroll inside Rich Text Box with scrollbars disabled
A better way of scrolling the RichTextBox control programmatically is by sending the EM_SCROLL message:
Code:
Private Const EM_SCROLL As Long = &HB5
Private Const SB_LINEUP As Long = 0
Private Const SB_LINEDOWN As Long = 1
Private Declare Function SendMessageW Lib "user32.dll" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Code:
If ActiveControl Is RTFTextBox Then
If Rotation > 0 Then
SendMessageW RTFTextBox.hWnd, EM_SCROLL, SB_LINEUP, 0&
Else
SendMessageW RTFTextBox.hWnd, EM_SCROLL, SB_LINEDOWN, 0&
End If
End If
BTW, when comparing controls or Object variables to see whether they are the same instance, use the Is operator instead of the = operator. In this line:
Code:
If Me.ActiveControl = Me.RTFTextBox Then
You are actually comparing the RichTextBox's default member (TextRTF) with the default member of the currently active control, which could possibly be nonexistent in the case of certain ActiveX controls or UserControls and would therefore raise an error ("Object doesn't support this property or method").