Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Mar 2001
    Location
    Leeds, UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Scrolling a Textbox

    How can I find the hWnd of a textbox control on a Userform? I want to be able to scroll a multiline textbox through code, so I think I need to use the SendMessage API function, but I need the hWnd of the control - VBA doesn't provide it.

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Scrolling a Textbox

    I think <A target="_blank" HREF=http://groups.google.com/groups?q=hWnd+of+a+textbox+control+on+a+Userform&h l=en&lr=&safe=off&rnum=1&ic=1&selm=39D45AC5.45112F 05@csv.warwick.ac.uk>this</A> answers your question (but I'm not sure) --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    New Lounger
    Join Date
    Mar 2001
    Location
    Leeds, UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scrolling a Textbox

    Thanks for this, Sam. I do appear to be able to get the hWnd of my textbox now, but sadly I can't make it scroll by sending it an EM_LINESCROLL message <img src=/S/weep.gif border=0 alt=weep width=21 height=16>. The link you gave me mentions:-

    "However, that textbox is not the standard Windows Editbox common control, so the EM_ messages do not necessarily apply."

    Any more ideas, anyone, on how to make my textbox scroll?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Scrolling a Textbox

    Check out this thread for some ideas : <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=40603&page=&view= &sb=&vc=1>Vertical Marquee</A>

    Andrew C

  5. #5
    New Lounger
    Join Date
    Mar 2001
    Location
    Leeds, UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scrolling a Textbox

    Andrew

    Thanks for your idea. I'd better explain just what I'm trying to do.

    I have a multiline textbox. When the user has entered text, I use the BeforeUpdate event to remove blank lines and trailing spaces. Because the text in the textbox has been rewritten, the scroll position is lost. I am trying to minimise the resultant jumping of the text, which is confusing to the user.

    As this doesn't appear to be as easy as I hoped, I think I'd better find a way of coding my app without modifiying the text box in the first place.

    I'm still curious, though, to know whether you can use code to move the scrollbar on a Userform textbox.

    Thanks for all your suggestions.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Scrolling a Textbox

    You can use code to do most things, even if it involved Windows API calls. However, I don't think you really want to scroll the textbox. What you want to do is position the cursor at a particular point in the textbox, which should scroll it automatically. Look up the SelText, SelStart and SelLength properties in help. They may help you get where you want to go.
    Charlotte

  7. #7
    New Lounger
    Join Date
    Mar 2001
    Location
    Leeds, UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scrolling a Textbox

    Hi Charlotte

    You're right up to a point. I do want to use the SelStart property to set the cursor position, but this still produces an annoying behaviour - the line with the cursor appears to jump to the top of the textbox because the textbox scrolls just as far as necessary to make it visible.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Scrolling a Textbox

    Then I'm obviously missing the point. I thought that's what you wanted it to do. Otherwise, where were you trying to scroll to? You could always set the starting point to the beginning of the text to scroll the textbox and then set it to the end to get back to the end of the text, if that's your intention.
    Charlotte

  9. #9
    New Lounger
    Join Date
    Mar 2001
    Location
    Leeds, UK
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Scrolling a Textbox

    The more I thought about this, the more I realised I was going about it the wrong way. My intention was the text in the textbox should appear to stay still after it had been processed i.e. that the line with the cursor should stay in the middle of the textbox if that's where it was.

    I now have a working solution which involves writing the processed text to a variable instead of back to the textbox, which is probably (no, definitely) the approach I should have taken all along.

    Thanks for your suggestions, everyone.
    (I'm still curious about how to make a textbox on a userform scroll even though I don't need to now! <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15> )

Posting Permissions

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