-
Mar 12th, 2016, 04:05 PM
#1
Thread Starter
Member
[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.
Last edited by Edelweise; Mar 12th, 2016 at 04:14 PM.
-
Mar 12th, 2016, 04:29 PM
#2
Thread Starter
Member
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
-
Mar 12th, 2016, 04:30 PM
#3
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.
Last edited by Magic Ink; Mar 12th, 2016 at 04:36 PM.
Reason: Good...
-
Mar 12th, 2016, 06:06 PM
#4
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").
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|