CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2001
    Posts
    5

    ScrollBar in TextBox

    I have TextBox wich displays several lines of text. Its height is enough to display 4 lines only. In case there are more than 4 lines I would like to add ScrollBar to the TextBox automatically. How can I do it?
    Thank you
    Vlad


  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: ScrollBar in TextBox

    Set its Scrollbars Property to 2(vertical).


  3. #3
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: ScrollBar in TextBox

    Text1.ScrollBars=vbVertical


  4. #4
    Join Date
    Aug 2001
    Posts
    5

    Re: ScrollBar in TextBox

    Thank you, but I do not want to have it always. I need the scrollbar only if displayed text doesn't fit the text box.
    Vlad


  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: ScrollBar in TextBox

    In that case, your simplest option is to use a richtextbox instead... it'll put them on for you, otherwise you have to use the Sendmessage API to add and remove the scrollbars...


  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: ScrollBar in TextBox

    Determine how many lines in the text box and if more than 4 display scroll bar.
    To count lines in the textbox

    Private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

    Const EM_GETLINECOUNT = &HBA



    'Call API to determine how many lines of text are in text box
    LinesOfText = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)


    and now you can
    if LineOfText>4 then
    Text1.ScrollBars = 2'vertical
    else
    Text1.ScrollBars = 0'none
    end if

    Iouri Boutchkine
    iouri@hotsheet.com
    Iouri Boutchkine
    iouri@hotsheet.NOSPAM.com

  7. #7
    Join Date
    Aug 2001
    Posts
    5

    Re: ScrollBar in TextBox

    Thank you very much. It's what I needed


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