Click to See Complete Forum and Search --> : ScrollBar in TextBox
vlad8682
October 3rd, 2001, 01:49 PM
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
DSJ
October 3rd, 2001, 01:58 PM
Set its Scrollbars Property to 2(vertical).
MKSa
October 3rd, 2001, 01:59 PM
Text1.ScrollBars=vbVertical
vlad8682
October 3rd, 2001, 02:02 PM
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
DSJ
October 3rd, 2001, 02:14 PM
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...
Iouri
October 3rd, 2001, 02:17 PM
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
iouri@hotsheet.com
vlad8682
October 3rd, 2001, 02:52 PM
Thank you very much. It's what I needed
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.