Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Prevent smooth scrolling of richtextbox control

Posted on 2003-04-01
5
Medium Priority
?
444 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

564 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