Results 1 to 4 of 4

Thread: simple question about a textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Israel
    Posts
    79

    Question simple question about a textbox

    how do i know my position inside a textbox?

    for example, if i have a textbox with multiline, and alot of text inside. the cursor is somewhere in the middle.
    how can i count - or get somehow the position of the cursor

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Use the SelStart property. It will return the current cursor position.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    See if this helps. Add a Label, and call it lblCurrLineNo
    VB Code:
    1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    2. ' Copyright ©1996-2001 VBnet, Randy Birch, All Rights Reserved.
    3. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    4. ' You are free to use this code within your own applications,
    5. ' but you are expressly forbidden from selling or otherwise
    6. ' distributing this source code without prior written consent.
    7. ' This includes both posting free demo projects made from this
    8. ' code as well as reproducing the code in text or html format.
    9. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    10.  
    11. 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
    12.  
    13. Private Const EM_LINEFROMCHAR = &HC9
    14.  
    15.  
    16.  
    17. Private Sub Text1_Change()
    18.  
    19.    'get the line the cursor is currently on
    20.     Dim currLine As Long
    21.  
    22.     On Local Error Resume Next
    23.     currLine = SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1&, ByVal 0&) + 1
    24.     lblCurrLineNo = Format$(currLine, "##,###")
    25.  
    26. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Israel
    Posts
    79
    thanks


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