Results 1 to 6 of 6

Thread: Lines property of textbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Lines property of textbox

    Working on an app where I want to print (among other things) the text in a textbox... I am having difficulties reading the individual lines in the textbox... I do the following

    VB Code:
    1. dim strLines() as string
    2.  
    3. strLines = textbox1.Lines

    Now I thought I got a string array representing each of the lines in the textbox, BUT I get only one string with all lines.

    Is there a problem with the new line or something? Or what is the definition of "line" in a textbox? I have the textbox with a size of 136;120 (pretty small)...


    UPDATE: The problem I have is that I have to press "return" in order for a new line to be recognized... But since I have wordwrap property set to true, it should add newline when I type beyond the width of the textbox, yes? Or how can I solve it???


    kind regards
    Henrik
    Last edited by MrNorth; Mar 31st, 2004 at 01:07 AM.

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I would assume the streamReader would simply read one line at a time and keep it as one line until it sees the newLine. Are you using a streamReader?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Hi!

    No its a simple textbox with multiline properties... No File I/O


    kind regards
    Henrik

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Lines property of textbox

    Originally posted by MrNorth

    UPDATE: The problem I have is that I have to press "return" in order for a new line to be recognized... But since I have wordwrap property set to true, it should add newline when I type beyond the width of the textbox, yes? Or how can I solve it???


    kind regards
    Henrik
    I believe the wordwrap inside the control has no bearing on the actual linefeeds or carriage returns contained in the text.

    The control artifically puts them in there, and systematically removes them when you access the underlying text.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Oh, thats sad. I guess I have to do it the hard way... check the length of textbox, get the width of the font in use and do some old fashion math to find out the approx. number of lettersper row... I do this on a drag/drop operation where I need to insert a listbox item at a specific row...

    Never thought I needed to use that on this simple stuff...or?


    kind regards
    Henrik

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, this was an old VB6 example of how to get the actual lines in a UI display of text from a windows base control.


    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias _
    2.         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
    3.         wParam As Long, ByVal lParam As Any) As Long
    4.        
    5. Private Const EM_GETLINE As Long = &HC4&
    6. Private Const EM_GETLINECOUNT As Long = &HBA&
    7. Private Const MAX_CHAR_PER_LINE As Long = &H100&
    8.  
    9. Private Sub Command1_Click()
    10.     Dim Max As Long, X As Long
    11.    
    12.     Max = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0& ) - 1
    13.     List1.Clear
    14.    
    15.     For X = 0 To Max
    16.         List1.AddItem GetLine(Text1, X)
    17.     Next X
    18. End Sub
    19.  
    20. Private Sub List1_Click()
    21.     Label1.Caption = List1.List(List1.ListIndex)
    22. End Sub
    23.  
    24. Function GetLine(Text As TextBox, ByVal Line& ) As String
    25.     Dim Lo As Long, Hi As Long
    26.     Dim Result As Long
    27.     Dim Buff As String
    28.  
    29.     Lo = MAX_CHAR_PER_LINE And &HFF
    30.     Hi = Int(MAX_CHAR_PER_LINE / &H100)
    31.     Buff = Chr$(Lo) & Chr$(Hi) & Space$(MAX_CHAR_PER_LINE - 2)
    32.    
    33.     Result = SendMessage(Text.hwnd, EM_GETLINE, Line, Buff)
    34.     GetLine = Left$(Buff, Result)
    35. End Function

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