Results 1 to 8 of 8

Thread: RichTextBox Question

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Is there any easy way to set the SelStart at the beginning of the current line (or at any line for that matter)

    I know you can get the current line but....

    Thanks
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Off the top of my head...
    Code:
    x = rtf.GetLineFromChar(rtf.SelStart)
    
    Do Until rtf.GetLineFromChar(rtf.SelStart) = x-1
      rtf.SelStart = rtf.SelStart -1
    Loop
    
    rtf.SelStart = rtf.SelStart + 1
    there's probably a hell of a lot easier way, but its late...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    or perhaps...can you SendKeys the HOME key? I don't know.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Here you go:
    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 EM_LINEINDEX = &HBB
    
    Public Sub JumpToStartOfLine(rtb As RichTextBox)
        rtb.SelStart = SendMessage(rtb.hWnd, EM_LINEINDEX, -1, 0)
    End Sub
    When you pass -1 in the wParam argument you'll get the first character position of the current line.
    You could pass any line number to this argument.

    Best regards

  5. #5
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    Joacim,

    A question related to your SendMessage solution...

    I've noticed that a lot of people use SendMessage for a lot of different things... what's the best way to find out what Messages to send to what types of forms/windows to get particular results?

    Thanks...
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

  6. #6

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Thanks Joacim ..thats PERFECT

    much faster now...(instead of starting at the beginning and rechcking verything...just does current line!)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Originally posted by Achichincle
    Joacim,

    A question related to your SendMessage solution...

    I've noticed that a lot of people use SendMessage for a lot of different things... what's the best way to find out what Messages to send to what types of forms/windows to get particular results?
    Ohhh.... There are thousands of different messages you can send.
    One source is of course the MSDN Library.
    You can for example search for messages starting with WM_????? or for TextBox and RTF boxes they start with EM_?????.
    For Command buttons, Checkboxes and Option buttons the messages starts with BM_???? or BN_?????

    Best regards

  8. #8
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    LoCal
    Posts
    280
    Joacim,

    Ok. Thanks. I see them in the MSDN now...
    Achichincle

    VB6 (VSEE SP5, W2KPro)
    ASP
    HTML

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