?
Solved

Prevent smooth scrolling of richtextbox control

Posted on 2003-04-01
5
Medium Priority
?
440 Views
Last Modified: 2013-12-25
Looking for a way to make the richtextbox control scroll a line at a time.  I have a custom control that implements line numbers by pairing a picture box and the richtextbox as constituent controls.  A timer checks the current line (via SendMessage) of the richtextbox and prints a range of line numbers to the picturebox.

The problem is that the user sees the smooth scrolling of the richtextbox, while the picturebox with the line numbers appears to jump to the next line.  So I need to either disable the smooth scrolling of the richtextbox or figure out how to make the printing of line numbers work on pixel boundaries.  I'm not opposed to subclassing if that's the only way to do it.
0
Comment
Question by:Nomlas
[X]
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
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:supunr
ID: 8249934
this is probably not the best way.

Private Sub Timer1_Timer()
    With Me.RichTextBox1
        .SetFocus
        SendKeys "{Down}"
    End With
End Sub

' Good Luck!
0
 

Author Comment

by:Nomlas
ID: 8252931
Thanks, but I need a way that still lets the user work the scroll bar in the normal manner.  
0
 

Author Comment

by:Nomlas
ID: 8253169
Thanks, but I need a way that still lets the user work the scroll bar in the normal manner.  
0
 
LVL 11

Accepted Solution

by:
supunr earned 750 total points
ID: 8257987
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

Dim m_iScrollDir As Integer

Private Sub Timer1_Timer()

    If (m_iScrollDir = 1) Then
         ' Send a WM_VSCROLL message 0 is up and 1 is down
           SendMessage Me.RichTextBox1.hwnd, 277&, 0&, vbNull
         Else 'Scroll Down
           SendMessage RichTextBox1.hwnd, 277&, 1&, vbNull
         End If
End Sub
0
 

Author Comment

by:Nomlas
ID: 8261461
Looking back at my question, I see that it could have been stated better.  

I'm looking for a way to override the default behavior of the richtextbox so that when the USER scrolls the box (by the vertical scroll bar or the up/down arrow)it will scroll only in complete line increments.  My scheme for keeping another control with line numbers in it synchronized to the RTB depends on line-incremental scrolling.

Right now, I'm subclassing the WM_VSCROLL and sending it to another RTB containing the line numbers.  This is OK when the user only uses the scroll bar but gets complicated when the user uses the keyboard arrows.  I don't see a message for up/down arrows and I don't want to go to the extra complexity of hooking the keyboard events.  If I knew the RTB would scroll in line increments, I could go to a simpler method of printing line numbers to a picturebox.  Plus I just don't like smooth scrolling for this particular application use.
 
Thanks....


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 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