CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    How to remove the inactive scroll bars till the text is big enough in multiline text box?

    Well, the subject says it all..

    If you set the Multiline property of a textbox to true, and set the scrollbar to say vertical, a vertical scroll bar is displayed all the time. I want it to display the scroll bar only when the text is big enough i.e outside the visible range? is it possible?
    API way is ok.
    I am doing some searching on my own.. meanwhile.. any ideas pointers...

    Thanks in advance

    RK

  2. #2
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to remove the inactive scroll bars till the text is big enough in multiline text box?

    I am answering my own post:
    Here is info for anybody who want to know about it:

    Use ShowScrollbar Api fn.

    Declare Function ShowScrollBar Lib "user32" (byval hwnd as Long, byval wBar as Long, byval bshow as Long) as Long
    Const SB_HORZ = 0
    Const SB_VERT = 1
    Const SB_CTL = 2 ' Applicable for a Scroll bar control Only
    Const SB_BOTH = 3




    RK

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to remove the inactive scroll bars .. Part III !!

    But there is something funny about it:

    IF you dont create a text box with scroll bars initally ( ie set ScrollBars = 0 , in design mode), and then just set the style with
    SetWindowLong.hwnd, GWL_STYLE, lstyle Or WS_VHSCROLL, the fn goes thru w/o Error
    and even
    lrtn = ShowScrollBar(.hwnd, SB_VERT, 1)
    also goes thru w/o error, but the scroll bar doesn't show!!

    Where as instead of SB_VERT, if you say SB_BOTH, in the above line, both scroll bars appear!!, any body want to investigate this??


    private Sub Text3_Change()
    Dim nl as Long, ll as Long
    Dim lstyle as Long
    Dim rect1 as RECT

    With Text3
    nl = SendMessage(.hwnd, EM_GETLINECOUNT, 0, byval &H0&)

    nl = SendMessage(.hwnd, EM_GETFIRSTVISIBLELINE, 0, byval &H0&)
    If nl <> 0 then
    Debug.print "First visible line:"; nl;
    lstyle = GetWindowLong(Text3.hwnd, GWL_STYLE)
    Debug.print "Style of text3 = 0x"; Hex$(lstyle);

    Debug.Assert (lstyle And &H4&) = &H4&
    If (lstyle And &H4&) = &H4& then
    ' it is a multi line text box.
    If (lstyle And WS_VSCROLL) = 0 then
    lstyle = lstyle Or WS_VSCROLL

    lrtn = SetWindowLong(.hwnd, GWL_STYLE, lstyle)
    If lrtn = 0 then
    MsgBox "Setwindow long failed with err code=" & Str(Err.LastDllError)
    End If

    lrtn = ShowScrollBar(.hwnd, SB_VERT, 1)
    ' apparently there is no way to find out, if the scroll bar
    ' is already visible. So just make it true always
    Debug.print "Show scrollbar returns:"; lrtn
    End If
    End If
    .Refresh
    End If
    End With

    End Sub




    However, if you create the window with V-Scrollbar intially, and hide it on the form load with ShowWindow(..,SB_VERT , 0), and just enable it when the size > visible size, then it works fine.

    RK

  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How to remove the inactive scroll bars .. Part III !!

    I think a text box has to specify that it has scrollbars when it is created (like a multi-line textbox) - ie. When VB does the CreateWindowEx call. As you know, it's nigh-on impossible to change these properties once your program is running so always use scrollbars in the textbox, just don't show them when required.

    Unless of course, you want to create your own TextBox control using the API ;-)

    (mind you, the guys over at http://vbaccelerator.com have already done this - it destroys and then recreates the window when you change one of 'those' properties).


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  5. #5
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to remove the inactive scroll bars .. Part III !!

    Hi Chris,

    I know that some properties need to be set before window creation and cannot be changed afterwords.
    But the question was "Why does it work for the case of SB_BOTH", unless ofcourse, vb is doing internally what guys at vbaccelerator are doing! :-)

    RK

  6. #6
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How to remove the inactive scroll bars .. Part III !!

    I'm not sure why it works with SB_BOTH - I discovered the ShowScrollBar stuff quite a while ago and only really used it to determine the client area of a control. I wouldn't imagine that VB is destroying the window then recreating it again (it only does that when you switch from IDE to run-time AFAIK).

    I suppose it could be one of those built in 'features' of VB and it's controls that we all learn to love.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured