|
-
Mar 31st, 2004, 01:03 AM
#1
Thread Starter
Frenzied Member
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:
dim strLines() as string
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.
-
Mar 31st, 2004, 08:42 AM
#2
Frenzied Member
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?
-
Apr 1st, 2004, 07:58 AM
#3
Thread Starter
Frenzied Member
Hi!
No its a simple textbox with multiline properties... No File I/O
kind regards
Henrik
-
Apr 1st, 2004, 08:32 AM
#4
I wonder how many charact
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.
-
Apr 1st, 2004, 08:35 AM
#5
Thread Starter
Frenzied Member
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
-
Apr 1st, 2004, 08:57 AM
#6
I wonder how many charact
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:
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, ByVal lParam As Any) As Long
Private Const EM_GETLINE As Long = &HC4&
Private Const EM_GETLINECOUNT As Long = &HBA&
Private Const MAX_CHAR_PER_LINE As Long = &H100&
Private Sub Command1_Click()
Dim Max As Long, X As Long
Max = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0& ) - 1
List1.Clear
For X = 0 To Max
List1.AddItem GetLine(Text1, X)
Next X
End Sub
Private Sub List1_Click()
Label1.Caption = List1.List(List1.ListIndex)
End Sub
Function GetLine(Text As TextBox, ByVal Line& ) As String
Dim Lo As Long, Hi As Long
Dim Result As Long
Dim Buff As String
Lo = MAX_CHAR_PER_LINE And &HFF
Hi = Int(MAX_CHAR_PER_LINE / &H100)
Buff = Chr$(Lo) & Chr$(Hi) & Space$(MAX_CHAR_PER_LINE - 2)
Result = SendMessage(Text.hwnd, EM_GETLINE, Line, Buff)
GetLine = Left$(Buff, Result)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|