Thanks for the link. I used the following API call. However this does not work with a TextBox you must use a Rich Edit Control for this to return the correct results.
Code:
Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_GETLINECOUNT = 186
Re: [RESOLVED] Count the number of lines in a textbox?
It doesn't work with a textbox for me. I have some text that is 22 lines long, in a textbox it returns 7 using EM_GETLINECOUNT, in a rich edit box it returns the correct 22.
Re: [RESOLVED] Count the number of lines in a textbox?
I think it may have to do with how each control does word-wrapping. Try adding a Rich Edit box to your form and increase the amount of characters in your Text2 like this and the results will not be the same between the two controls:
Re: [RESOLVED] Count the number of lines in a textbox?
still not getting any problems (see attached) - you might get 1 or 2 lines difference do to character spacing (assuming the controls are the same width) - but EM_GETLINECOUNT still returns the correct number of lines.