Results 1 to 8 of 8

Thread: [RESOLVED] Thanks and scrollbars

  1. #1

    Thread Starter
    Lively Member eusty's Avatar
    Join Date
    Jan 2006
    Location
    UK
    Posts
    71

    Resolved [RESOLVED] Thanks and scrollbars

    First of a big thanks to everyone on here, I only popped here a while ago to just ask a question, but have stayed, and now my project is better than I could have done without you guys

    There doesn't seem to be any VB question that someone doesn't know the answer to...and is willing to help.


    One little question on textbox scrollbars, is there an easy way to get them to disappear when not needed, rather than just going lowlighted?
    Last edited by eusty; Jan 24th, 2006 at 05:51 PM.
    Steve

    No trees were cut down or harmed in the posting of this message. A lot of electrons were, however, severely inconvenienced.

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Thanks and scrollbars

    I don't know if there is any way to 'properly' show/hide scrollbars of a normal textbox at runtime.
    This code shows an alternate way to hide scrollbars in a Webbrowser control by using a picturebox container. I guess with very little modification it will work with normal textboxes too.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Thanks and scrollbars

    I just did this, using this code by Martinliss to show/hide scrollbars.

    I used a textbox named text1.
    In design mode, Set Multiline property = true and Scrollbars property = Both
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShowScrollBar Lib "user32" _
    4.                         (ByVal hWnd As Long, ByVal wBar As Long, _
    5.                         ByVal bShow As Long) As Long
    6.  
    7. Private Const SB_HORZ = 0
    8. Private Const SB_VERT = 1
    9. Private Const SB_HWND = 2
    10. Private Const SB_BOTH = 3
    11.  
    12. Private Const EM_GETLINECOUNT = &HBA
    13. Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" _
    14.                         (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam _
    15.                         As Long, ByVal lParam As Long) As Long
    16.  
    17. Private Sub Form_Load()
    18.     CheckScrollBars
    19. End Sub
    20.  
    21. Private Sub Text1_Change()
    22.     CheckScrollBars
    23. End Sub
    24.  
    25. Private Sub CheckScrollBars()
    26. Dim lngLineCount As Long
    27. Static VVisible  As Boolean
    28. Static HVisible  As Boolean
    29. Dim lWidth       As Long
    30. Dim lHeight      As Long
    31. Dim i            As Integer
    32.  
    33.     lngLineCount = SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
    34.    
    35.     For i = 1 To 2 '2 times, because if HScrollbar appeared, VScrollbar code will be different
    36.        
    37.         'If Horizontal ScrollBar is present, Height = Text1.Height - [Height of the Hscrollbar]
    38.         If HVisible Then lHeight = Text1.Height - 250 Else lHeight = Text1.Height - 150
    39.        
    40.         If Me.TextHeight("A") * lngLineCount > lHeight Then
    41.             ShowScrollBar Text1.hWnd, SB_VERT, True  'Higher than Height?
    42.             VVisible = True                          'Make VScrollbar visible
    43.         Else
    44.             ShowScrollBar Text1.hWnd, SB_VERT, False 'Hide VScrollbar
    45.             VVisible = False
    46.         End If
    47.        
    48.         'If Vertical ScrollBar is present width = Text1.width - [width of the Vscrollbar]
    49.         If VVisible Then lWidth = Text1.Width - 350 Else lWidth = Text1.Width - 100
    50.        
    51.         If Me.TextWidth(Text1.Text) > lWidth Then    'Wider than width?
    52.             ShowScrollBar Text1.hWnd, SB_HORZ, True  'Make HScrollbar visible
    53.             HVisible = True
    54.         Else
    55.             ShowScrollBar Text1.hWnd, SB_HORZ, False 'Hide HScrollbar
    56.             HVisible = False
    57.         End If
    58.     Next
    59. End Sub
    Last edited by jcis; Jan 25th, 2006 at 01:47 AM.

  4. #4
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Thanks and scrollbars

    Ah ! I didn't figured out that we need to put that code in Text_Change too !
    Jcis, your code is running perfectly here.

    Edit: Here is a little modified version of jcis's code that works on SingleLine textboxes.
    Last edited by iPrank; Jan 23rd, 2007 at 01:01 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  5. #5

    Thread Starter
    Lively Member eusty's Avatar
    Join Date
    Jan 2006
    Location
    UK
    Posts
    71

    Re: Thanks and scrollbars

    Although it doesn't work on form_resize.

    I have a text box which just displays data (.locked=true), and the code just removes the scrollbars.

    On loading if the text to too long for the box it desn't wrap the text, and the same is true on the resize.
    Steve

    No trees were cut down or harmed in the posting of this message. A lot of electrons were, however, severely inconvenienced.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Thanks and scrollbars

    I tryied with a locked textbox and its working fine.
    You are resizing the textbox in form_resize event or something like that?
    Quote Originally Posted by eusty
    On loading if the text to too long for the box it desn't wrap the text..
    You want it to wrap the text? So why you use scrollbars then?
    Or maybe you want to use just the vertical scrollbar?
    Last edited by jcis; Jan 25th, 2006 at 05:55 PM.

  7. #7

    Thread Starter
    Lively Member eusty's Avatar
    Join Date
    Jan 2006
    Location
    UK
    Posts
    71

    Re: Thanks and scrollbars

    Yes I just want the vertical scrollbar, if it's needed.

    I'm using the form_resize control to change the size of the whole form, including the textbox.
    With the scrollbar code added, when you resize the text just 'disappears' under the form rather than the vertical scrollbar appearing.

    The form_resize calls the scrollbar code and it runs it, but all values returned are false so it doesn't add them.
    Steve

    No trees were cut down or harmed in the posting of this message. A lot of electrons were, however, severely inconvenienced.

  8. #8

    Thread Starter
    Lively Member eusty's Avatar
    Join Date
    Jan 2006
    Location
    UK
    Posts
    71

    Re: Thanks and scrollbars

    Just needed a new day and another look at the code
    Steve

    No trees were cut down or harmed in the posting of this message. A lot of electrons were, however, severely inconvenienced.

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