Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I hide the scrollbar on a multiline textbox?

Status
Not open for further replies.

PatrioticTX

Programmer
Dec 5, 2001
18
US
I would like to hide the scrollbar on a multiline textbox if the amount of text does not exceed the visible bounds. For example, if the textbox height allows the display of two text lines, and up to two lines are typed in, I do not want the scrollbar to be visible (VB default is to disable the scrollbar). Once the number of lines typed exceeds two, I want the scrollbar to be visible.

Is there some type of property that I am overlooking that can return the number of lines displayed?

I was originally going to set the scrollbar to be visible when the control had focus, but the
Code:
scrollbars
property is readonly at runtime.
 
Code:
Function GetNoLines(strIN as string) as long
    Dim lngLines as long
    Dim I as long
    if Len(strW) > 0 then  ' 0 lines if no chars
        lngLines = 1
        I = 1
        Do
            I = Instr(I,strW,vbcrlf)
            If I = 0 then exit do
            lnglines = lnglines + 1
            I = I + 2 
        Loop  
    End if
    GetNoLines = lngLines
End Function
Compare Code (Text)
Generate Sort in VB or VBScript
 
Thank you for your suggestion. Unfortunately, the above code only works if the user forces a new line with a CRLF. If the text is auto wrapped, it will not return the number of lines. After more consideration, I don't think that knowing the number of lines will help me because I can not set the
Code:
multiline
or
Code:
scrollbars
properties.
 
Option Explicit
Private Const SB_VERT = 1
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long

Private Sub Text1_Change()
On Error Resume Next
Dim lReturn As Long
lReturn = ShowScrollBar(Text1.hWnd, SB_VERT, bScroll())
End Sub

The above code illustrates the use of ShowScrollBar Win32API to show/hide the scroll bar of an Edit Control. It is assumed that the logic of deciding to Show/Hide the scroll bar would go into the function 'bScroll' which would return a True/False value to the caller.

For more information on ShowScrollBar API, please see the MSDN under Platform SDK: Windows User Interface
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top