I have TextBox wich displays several lines of text. Its height is enough to display 4 lines only. In case there are more than 4 lines I would like to add ScrollBar to the TextBox automatically. How can I do it?
Thank you
Vlad
Printable View
I have TextBox wich displays several lines of text. Its height is enough to display 4 lines only. In case there are more than 4 lines I would like to add ScrollBar to the TextBox automatically. How can I do it?
Thank you
Vlad
Set its Scrollbars Property to 2(vertical).
Text1.ScrollBars=vbVertical
Thank you, but I do not want to have it always. I need the scrollbar only if displayed text doesn't fit the text box.
Vlad
In that case, your simplest option is to use a richtextbox instead... it'll put them on for you, otherwise you have to use the Sendmessage API to add and remove the scrollbars...
Determine how many lines in the text box and if more than 4 display scroll bar.
To count lines in the textbox
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
Const EM_GETLINECOUNT = &HBA
'Call API to determine how many lines of text are in text box
LinesOfText = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
and now you can
if LineOfText>4 then
Text1.ScrollBars = 2'vertical
else
Text1.ScrollBars = 0'none
end if
Iouri Boutchkine
[email protected]
Thank you very much. It's what I needed