|
-
Jan 17th, 2003, 07:59 PM
#1
Thread Starter
Junior Member
Scrolling a RichTextBox
Ok, here's my problem. I have a RighTextBox, and I want my program to be able to automatically scroll the Horozontal scrollbar all the way back to the left. I tryed using the SendMessage API with the EM_SCROLL message, but I can't seem to get it to work. Any ideas?
-
Jan 18th, 2003, 08:01 AM
#2
PowerPoster
a quick "cheat" would be something like:
richtextbox1.selstart = 0
if that helps ...
-
Jan 18th, 2003, 09:38 AM
#3
Let me in ..
Re: Scrolling a RichTextBox
Originally posted by Jdo300
Ok, here's my problem. I have a RighTextBox, and I want my program to be able to automatically scroll the Horozontal scrollbar all the way back to the left. I tryed using the SendMessage API with the EM_SCROLL message, but I can't seem to get it to work. Any ideas?
EM_Scroll would not help.
use these constants ..
VB Code:
Private Const SB_LINEDOWN As Long = 1
Private Const SB_LINEUP As Long = 0
Private Const SB_PAGEDOWN As Long = 3
Private Const SB_PAGEUP As Long = 2
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H115
'examples :
intRet = SendMessage(richtextbox1.hwnd, _
WM_HSCROLL, _
SB_LINEUP, 0)
'and
intRet = SendMessage(richtextbox1.hwnd, _
WM_VSCROLL, _
SB_PAGEUP, 0)
'And your rtb will scroll like hell ..
-
Jan 18th, 2003, 02:43 PM
#4
Thread Starter
Junior Member
Ohhh ok. sure that sounds good, but a couple of problems there:
1. I need to scroll ONLY the horozontal scrollbar all the way to the left
2. the textbox would have a highlighted block of text in it, so I couldn't change anything with the SelStart,len,text properties.
3. I also looked up the EM_GETSCROLLPOS & EM_SETSCROLLPOS properties since the textbox i'm using is a RichTextBox, but I wrote a function like:
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER As Long = &H400
Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
Private Type POINTAPI
x As Long
Y As Long
End Type
'Moves the Horozontal scrollbar in txtWindow all the way to the left
Public Function MoveScrollBar(RTB As RichTextBox)
Dim PointX As POINTAPI 'X,Y struct containing the scroll position of the RichTextBox
'Fill the PointX structure so the current Y position can be retrieved
SendMessage RTB.hwnd, EM_GETSCROLLPOS, 0, PointX
'Set the X to zero
PointX.x = 0
'Update the scrollbar position
SendMessage RTB.hwnd, EM_SETSCROLLPOS, 0, PointX
RTB.Refresh
End Function
and of course, it didn't work! I need help
-
Jan 18th, 2003, 04:44 PM
#5
The picture isn't missing
it won't work because a richtextbox is not a textbox... amd EM_ messages are only for TEXTboxes.
Remember, if someone's post was not helpful, you can always rate their post negatively  .
-
Jan 18th, 2003, 05:16 PM
#6
Originally posted by BuggyProgrammer
it won't work because a richtextbox is not a textbox... amd EM_ messages are only for TEXTboxes.
That's not true at all. Most EM_xxxx messages will work for both rich and regular edit boxes.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 18th, 2003, 05:28 PM
#7
Try this...
VB Code:
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Const WM_HSCROLL = &H114
Private Const SB_LEFT = 6
Private Const SCROLL_AMT = 100& 'Increase as necessary
Public Function MakeDWord(LoWord As Long, HiWord As Long) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
'usage
Call SendMessageLong(RichTextBox1.hwnd, WM_HSCROLL, MakeDWord(SB_LEFT, SCROLL_AMT), 0&)
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 18th, 2003, 06:17 PM
#8
Thread Starter
Junior Member
Thanks! It works great! But I have yet another problem! The reason I needed the horizontal scrollbar to automatically go left is because I've made some code that can block tab text, and I didn't want the box to scroll right when the text is tabbed. Now, the code you gave me works fine, but the whole box blinks whenever the scrollbar is adjusted. Is there a way to simply keep the textbox from scrolling right when the text is tabbed?
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
|