Results 1 to 9 of 9

Thread: Scroll bar in Textbox(thanks to JCIS)

Hybrid View

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

    Show/hide Scrollbar On a SingleLine TextBox

    Here is a little modified version of jcis's code that works on SingleLine textboxes.
    This is actually a MultiLine text box, but it simulates like a singleline textbox.

    Set Multiline = True and Scrollbar = Horizontal at designtime.
    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.  
    9. Private Sub Form_Load()
    10.     CheckScrollBars
    11. End Sub
    12.  
    13. Private Sub Text1_Change()
    14.     CheckScrollBars
    15. End Sub
    16.  
    17. Private Sub CheckScrollBars()
    18.  
    19.     If Me.TextWidth(Text1.Text) > (Text1.Width - 100) Then    'Wider than width?
    20.         ShowScrollBar Text1.hWnd, SB_HORZ, True  'Make HScrollbar visible
    21.     Else
    22.         ShowScrollBar Text1.hWnd, SB_HORZ, False 'Hide HScrollbar
    23.     End If
    24.  
    25. End Sub
    26.  
    27. Private Sub Text1_KeyPress(KeyAscii As Integer)
    28.     If KeyAscii = 10 Or KeyAscii = 13 Then KeyAscii = 0
    29. End Sub
    Last edited by iPrank; Jan 23rd, 2007 at 11:19 AM.
    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


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