Scrolling a Textbox

Posted on 2000-04-25
Last Modified: 2008-03-10
I have tried the scrollwindowex api function, but it doesn't work and i don't want to use a listbox for it.
Question by:frogman_j
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 28

Accepted Solution

Ark earned 100 total points
ID: 2749943
Do you want to scroll TextBox line-by-line or pixel-by-pixel?
If line-by-line, its simply:
Const EM_SCROLL = &HB5
Const SB_LINEUP = 0
Const SB_PAGEUP = 2
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Private Sub Command2_Click()
  Dim nRet As Long
  nRet = SendMessageByNum(Text1.hwnd, EM_SCROLL, SB_LINEDOWN, 0&)
End Sub

Pixel-by-pixel solution is a bit harder. I did this code for RichTextBox, but for ordinary TextBox it's the same:


Expert Comment

ID: 2750269
try this : put a lotta text into the textbox. somewhere towards the end u add "FIND THIS"

put this into a command button

Text1.SelStart = InStr(1, Text1, "FIND THIS")
Text1.SelLength = 0
' be sure to put this setfocus line in

NOte : instead of the "FIND THIS TEXT" and the instring, u can simply add an average no of chars and repeat this in a timer to create a cute scroll effect.
Hope this solves ur problem .

ARK too has a nice solution for pixels...

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 2757156
I used a modification of Ark's code, so put in an answer Ark!

Author Comment

ID: 2757158
never mind, Ark

Author Comment

ID: 2757164
Thanks for the bit of code. I looked at more of the SB_ constants and I can use it like I want now.

Author Comment

ID: 2757184
Just one more question. Is there a way to scroll to the bottom cleanly?
LVL 28

Expert Comment

ID: 2757262
Thanks for points, glad to help you!
About scrolling to bottom - it's simply - no API
Text1.SelStart = Len(Text1.Text)

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question