Results 1 to 11 of 11

Thread: RichTextbox Woahs

  1. #1

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336

    RichTextbox Woahs

    OK i am using an RTB and i have the Word wrap turned off with a bit of API. So it acts like a listbox.

    Here is the code i use to do that.

    VB Code:
    1. Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    2. Public Const WM_USER = &H400
    3. Public Const EM_SETTARGETDEVICE = (WM_USER + 72)
    4.  
    5. Private Sub RT_Change()
    6. SendMessageLong RT.hWnd, EM_SETTARGETDEVICE, 0, 1
    7. End Sub
    8.  
    9. If RT.TExt <> "" Then
    10. RT.Text = RT.Text & vbCrLf & sItem
    11. Else
    12. RT.Text = sItem
    13. End If


    I also have it so that when i click on the RIchtextbox it selects the text i click on.

    VB Code:
    1. Private Sub RT_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. SendKeys "{HOME}"
    3. End Sub
    4.  
    5. Private Sub RT_Click()
    6. On Error Resume Next
    7. Dim a As String
    8. a = RT.GetLineFromChar(RT.SelStart)
    9. RT.SelLength = Len(a)
    10. End Sub

    my ONLY problem with this is when i click on an item that is longer than the RTB is wide, it scrolls over to the end of the selected text.

    I dont want it to do that! i want it to select the text and stay where it is. So it acts like a listbox.

    I either need it to select the text and NOT have the cursor move or once the cursor Moves i need it to move back to the beggining of the text. OR IF i can't move the cursor without unselecting the text i need to scroll back to the left side of the RTB somehow and leave the text selected.
    Code:
    I.e.
                if the RTB Starts here|and ends here     |
                                      |                  |
                                      |DFGDFGDFGDFGDFGDDFgdfgdfgdfgdfg
                                      |                  |
                                      |                  |
    well then it scrolls to where the lower case letters are. I need it to scroll back to the first UCase "D".




    THere must be some way to do this. Either with API or regular RTB methods. PLEASE HELP!

    Let me say that this code is taken from a big project so it doesnt work exactly as i have explained it. I left alot out for simplicity sake.


    Thanks alot
    Last edited by Arc; Dec 12th, 2001 at 04:11 PM.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    after selecting the text just set the cursor postion or sel start back to the start of the line

    that will stop it scrolling

  3. #3

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Yah it stops it from scroling but it also DESELECTS THE TEXT! Which is what i DONT want to happen
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    you could use send message api and the setcursorlocation

    I cant remember the link but if you do a search for cursorpostion and textbox on msdn you should find it

  5. #5

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Hmm sounds like a possibility. IF anyone is good at that API stuff feel free to chime in
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  6. #6

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Bumpage
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You could simply send the WM_HSCROLL message to scroll to the start.
    Simply pass SB_PAGELEFT in the wParam of SendMessage.
    Since you pass the message to a RTB the lParam should be 0.
    Is this about the same thing you asked before about moving the caret?
    In that case this explenation about what you're trying to achieve is much easier to understand

    Best regards

  8. #8

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Cool i'll give it a shot!
    What are the Constants for WM_HSCROLL & SB_PAGELEFT?

    The APi i can find the constans i have no clue where to find.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  9. #9

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    I tried guessing at the values of the constants to no avail. Perhaps you can fill me in Joacim?

    Thanks alot!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sure!
    VB Code:
    1. Private Const WM_HSCROLL = &H114
    2. Private Const SB_PAGELEFT = 2
    They do both exist in the API Viewer.
    Click the combo box named "API Type" and pick Constants to see all constants (well all that are included with the API Viewer anyway).
    There is also a better API Viewer application available at: www.allapi.net

    Best regards
    Last edited by Joacim Andersson; Dec 13th, 2001 at 01:51 AM.

  11. #11

    Thread Starter
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Joacim. I am using the API you suggested. however it doesnt do anything. No errors or anything, it's just like the code isnt event there.

    I am using it like this.

    Call SendMessage(RT.hwnd, WM_HSCROLL, SB_PAGELEFT, 0)

    Where RT is the name of the RTB. I am using it in the RT_Click event but i have tried it several ways to no avail.

    Any ideas?

    Thanks.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


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