Determine the numbers of lines in a textbox

  • Thread starter Thread starter Tom McLaughlin
  • Start date Start date
T

Tom McLaughlin

How can I determine the numbers of lines of text
that are visible in a textbox?

Tom
 
Hi Tom,

Textbox1.lines gives you the lines in a texbox.

Line is a difficult subject here, it is a line of text closed with a crlf
(enter key)

For getting the drawed lines I did till now not find a simple way. That is
because I could not get the soft CR that is made by the textbox when there
is a linewrap. I did not try it very deep, just with standard solutions.
(I did till now also not see a solution in this newsgroup for this)

I hope this helps?

Cor
 
Tom McLaughlin said:
How can I determine the numbers of lines of text
that are visible in a textbox?

In addition to Cor, Textbox.lines.length returns the number of lines.
 
* "Tom McLaughlin said:
How can I determine the numbers of lines of text
that are visible in a textbox?

Seems to be a FAQ:

\\\
MsgBox(Me.TextBox1.Lines.Length.ToString())
///
 
Thanks for all the suggestions but what I am looking for are the number of
lines
that will be visible when the text is greater then the textbox can display.
In other words,
The textbox is a rectangle of a certain size and can only hold so many lines
of text
according to the font that is being used. How can I determine this?
The following code worked fine in visual basic 5 but with my limited
knowledge of
..net I am not sure how to change the API calls.



'
' Determines the number of lines actually visible in the
' text control.
'
'
Private Function GetVisibleLines%()
Dim rc As Rect
Dim hdc%
Dim lfont%, oldfont%
Dim tm As TEXTMETRIC
Dim di%

' Get the formatting rectangle - this describes the
' rectangle in the control in which text is placed.
lc% = SendMessage(Text1.hWnd, EM_GETRECT, 0, rc)

' Get a handle to the logical font used by the control.
' The VB font properties are accurately reflected by
' this logical font.
lfont% = SendMessageBynum(Text1.hWnd, WM_GETFONT, 0, 0&)

' Get a device context to the text control.
hdc% = GetDC(Text1.hWnd)

' Select in the logical font to obtain the exact font
' metrics.
If lfont% <> 0 Then oldfont% = SelectObject(hdc%, lfont%)

di% = GetTextMetrics(hdc%, tm)
' Select out the logical font
If lfont% <> 0 Then lfont% = SelectObject(hdc%, oldfont%)

' The lines depends on the formatting rectangle and font height
GetVisibleLines% = (rc.bottom - rc.Top) / tm.tmHeight

' Release the device context when done.
di% = ReleaseDC(Text1.hWnd, hdc%)
End Function
 
Hi Tom,

Have a look at a message from Paul Mars on 25 of december.

"Count lines of text".

There are a lot of answers, I also made some examples to measure the lines
in the combobox.

But as I wrote before in this thread, the automatic (hidden) linefeed with a
wordwrap I could not measure.

Cor
 
Back
Top