Results 1 to 9 of 9

Thread: Scroll bar in Textbox(thanks to JCIS)

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Scroll bar in Textbox(thanks to JCIS)

    Dear All,
    I found this (thanks to JCIS)code to set the scroll bar to text box when it necessary.It works good .But i face one problem.It is not scrolling when i click the scroll bar.Can some body help. I studied the problem as I have set the multiline to False, ,Because I dont want to allow the user to type more than one line
    Last edited by danasegarane; Jan 23rd, 2007 at 09:54 AM.
    Please mark you thread resolved using the Thread Tools as shown

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

    Re: Scroll bar in Textbox(thanks to JCIS)

    That code is working perfectly for me.
    Did you remember to "Set Multiline property = true and Scrollbars property = Both" at design time ?
    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

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Scroll bar in Textbox(thanks to JCIS)

    Dear IPrank,
    I want to restrict the user to only one line.So I set the Multiline=False.Is there any method to solve this issue?
    Please mark you thread resolved using the Thread Tools as shown

  4. #4
    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


  5. #5

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Scroll bar in Textbox(thanks to JCIS)

    Dear IPrank,
    Thanks for your reply.It is not scrolling.?
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Scroll bar in Textbox(thanks to JCIS)

    If the user can only type one line of text what is there to scroll?

  7. #7

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Scroll bar in Textbox(thanks to JCIS)

    If the Text contents is more than the width of the textbox then there should be scrollbar to scroll.?
    Please mark you thread resolved using the Thread Tools as shown

  8. #8

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Scroll bar in Textbox(thanks to JCIS)

    I think I can close this thread if this is solved
    Please mark you thread resolved using the Thread Tools as shown

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

    Re: Scroll bar in Textbox(thanks to JCIS)

    Edited my previous code. it should work now.
    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