Results 1 to 14 of 14

Thread: RichTextBox scroll like a TextBox [unsolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397

    RichTextBox scroll like a TextBox [unsolved]

    If you have noticed, the TextBox scrolls down one line at a time while the RichTextBox scrolls down smoothly.

    Since im using a richtextbox, How can I make it so when the user scrolls down via the Vertical scroll bar its scrolls down one line a time like the textbox instead of the smooth scrolling of the richtextbox?
    Last edited by Narfy; Jan 28th, 2004 at 07:42 PM.

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    hmm

    If there isn't a property to do it, SendMessage probably can help you... but... Why would you want it to scroll one line at a time? Why not just use a listbox or a normal textbpx ?
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    i want it to scroll one line at a time because im making a line numbering control and i cant get the line numbers to match exactly up with the text in a richtextbox because of the smooth scrolling, but i can get them to line up in the textbox because of the one-line-at-a-time scrolling.

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    You could subclass as vbNeo suggests, or better still make your own User Control

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    is there a example anywere on how to do a subclass?

  6. #6
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Not sure, i believe its the hardest thing to do in VB

    Woka, Marty or someone else should be able to help you more.

  7. #7
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    or MerrionComputing, drop them a mail
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    Ive been searching like mad to try to find a answer, and i found this in the Developers Pad Source code, they use a richtextbox and it scrolls one line at a time

    im using the vbaccelerator subclassing
    http://www.vbaccelerator.com/home/VB...Tmr_Binary.asp

    VB Code:
    1. Implements ISubclass
    2.  
    3. Private Type POINTAPI
    4.         x As Long
    5.         y As Long
    6. End Type
    7.  
    8. Private Const WM_USER = &H400
    9. Private Const WM_MOUSEWHEEL = &H20A
    10. Private Const WM_VSCROLL = &H115
    11. Private Const EM_GETSCROLLPOS = (WM_USER + 221)
    12. Private Const EM_SETSCROLLPOS = (WM_USER + 222)
    13. Private Const WM_LBUTTONDOWN = &H201
    14.  
    15. 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
    16. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
    17. Private Declare Function GetScrollPos Lib "USER32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
    18.  
    19. Private lPixelsPerLine    As Long
    20. Private bResizingTriggered  As Boolean
    21.  
    22. Private Property Let ISubclass_MsgResponse(ByVal RHS As EMsgResponse)
    23. End Property
    24.  
    25. Private Property Get ISubclass_MsgResponse() As EMsgResponse
    26.     Select Case CurrentMessage
    27.     Case WM_VSCROLL, WM_MOUSEWHEEL
    28.         ISubclass_MsgResponse = emrConsume
    29.     Case Else
    30.         ISubclass_MsgResponse = emrPreprocess
    31.     End Select
    32. End Property
    33. Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    34. Dim iScrollPos As Long
    35. Dim bScrolling As Boolean
    36. Dim tp As POINTAPI
    37.     ' scroll events
    38.     Select Case iMsg
    39.     Case WM_MOUSEWHEEL
    40.         'go up or down 3 lines...
    41.         SendMessage hwnd, EM_GETSCROLLPOS, 0, tp
    42.         If wParam > 0 Then
    43.             tp.y = tp.y - (lPixelsPerLine * 5)
    44.         Else
    45.             tp.y = tp.y + (lPixelsPerLine * 5)
    46.         End If
    47.         SendMessage hwnd, EM_SETSCROLLPOS, 0, tp
    48.         DrawLines picLines, txtDocument
    49.     Case WM_VSCROLL
    50.         'are we scrolling, or scrolled?
    51.         bScrolling = (LoWord(wParam) = 4 Or LoWord(wParam) = 5)
    52.         If bScrolling Then
    53.             'get info using wparam
    54.             iScrollPos = HiWord(wParam)
    55.         Else
    56.             'call api
    57.             iScrollPos = GetScrollPos(hwnd, 1)
    58.         End If
    59.        
    60.         'update lines
    61.         If Int(iScrollPos / lPixelsPerLine) <> (iScrollPos / lPixelsPerLine) Then
    62.             'not divisible by 16
    63.             'we are showing half a line...
    64.             If bScrolling Then
    65.                 wParam = MakeDWord(LoWord(wParam), Int(iScrollPos / lPixelsPerLine) * lPixelsPerLine)
    66.             Else
    67.                 'hmm...
    68.             End If
    69.         End If
    70.         'send message to rtf for processing
    71.         ISubclass_WindowProc = CallOldWindowProc(hwnd, iMsg, wParam, lParam)
    72.         'update the lines
    73.         DrawLines picLines, txtDocument
    74.         'reset flags
    75.         bResizingTriggered = False
    76.         If wParam = 8 Then '8=SB_END... scroll end
    77.  
    78.         ElseIf wParam > 1 Then 'not up/down button
    79.  
    80.         End If
    81.     Case WM_LBUTTONDOWN
    82.         Debug.Print lParam
    83.     End Select
    84. End Function
    85.  
    86. Private Function LoWord(dwValue As Long) As Integer
    87.     CopyMemory LoWord, dwValue, 2
    88. End Function
    89. Private Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
    90.     MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    91. End Function
    92. Private Function HiWord(dwValue As Long) As Integer
    93.     CopyMemory HiWord, ByVal VarPtr(dwValue) + 2, 2
    94. End Function

    it doesn't do anything but it works in developers pad but not in my program, i get a illegal operation then vb6 crashes.
    anyone know what the problem is?

  9. #9
    Hyperactive Member Dasiths's Avatar
    Join Date
    Apr 2001
    Location
    Colombo, Sri Lanka
    Posts
    331

    try this

    http://www.elitevb.com/content/01,0099,01/

    exactly what you want ........

    Can you in return help me ...

    Dasith [email protected]
    25-Jan-04


    Is it possible to add a Black Line to indicate the end of the page (printer.height) .... So the user knows when a page ends and a new page starts ..

    Like in ms word you get a line to indicate page margins ...

    please email me if you can do it [email protected]
    It is the mark of an instructed mind to rest satisfied with the degree of precision which the nature of the subject admits, and not to seek exactness when only an approximation of the truth is possible.
    -Aristotle As quoted in Rapid Development, chapter 8, page 167.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    thanks, but it didn't work, the richtextbox they have in that project, it doesn't scroll one line at a time

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    bump

    cmon, someone has got to know :P

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    bump

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    cmon, someone answer, im desperate ive been searching everywhere

  14. #14
    Hyperactive Member Dasiths's Avatar
    Join Date
    Apr 2001
    Location
    Colombo, Sri Lanka
    Posts
    331

    what you want is a line numbered rtf control ...

    try my above example ....... it has a line numbered rich text control
    It is the mark of an instructed mind to rest satisfied with the degree of precision which the nature of the subject admits, and not to seek exactness when only an approximation of the truth is possible.
    -Aristotle As quoted in Rapid Development, chapter 8, page 167.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width