Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get textbox (rich or plain) to remain scrolled to the bottom?

How to get textbox (rich or plain) to remain scrolled to the bottom?

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sherifffruitfly
    wrote on last edited by
    #1

    Hi, I use textboxes to log application messages sometimes, and want them to stay scrolled to the bottom (most recent message). How can this be achieved? I've tried both textbox.text += "my message", and textbox.appendtext("my message") - they don't perform the behavior I'm after. Thanks for any ideas, cdj

    M S D 3 Replies Last reply
    0
    • S sherifffruitfly

      Hi, I use textboxes to log application messages sometimes, and want them to stay scrolled to the bottom (most recent message). How can this be achieved? I've tried both textbox.text += "my message", and textbox.appendtext("my message") - they don't perform the behavior I'm after. Thanks for any ideas, cdj

      M Offline
      M Offline
      Mudsoad
      wrote on last edited by
      #2

      try using this: textbox.text= "my message" + textbox.text hopes it helps, Wachill Signature has been encrypted

      S 1 Reply Last reply
      0
      • S sherifffruitfly

        Hi, I use textboxes to log application messages sometimes, and want them to stay scrolled to the bottom (most recent message). How can this be achieved? I've tried both textbox.text += "my message", and textbox.appendtext("my message") - they don't perform the behavior I'm after. Thanks for any ideas, cdj

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        Try calling ScrollToCaret after appending the new text.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        1 Reply Last reply
        0
        • S sherifffruitfly

          Hi, I use textboxes to log application messages sometimes, and want them to stay scrolled to the bottom (most recent message). How can this be achieved? I've tried both textbox.text += "my message", and textbox.appendtext("my message") - they don't perform the behavior I'm after. Thanks for any ideas, cdj

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Stefan is right. ScrollToCaret is what you're looking for. The only pitfall to using it, though, is that the TextBox has to have the input focus in order for it to work. Call the Focus method on the TextBox before you call ScrollToCaret.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          S 1 Reply Last reply
          0
          • M Mudsoad

            try using this: textbox.text= "my message" + textbox.text hopes it helps, Wachill Signature has been encrypted

            S Offline
            S Offline
            sherifffruitfly
            wrote on last edited by
            #5

            It would, were I willing to accept reverse chronological order. Thanks though!

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              Stefan is right. ScrollToCaret is what you're looking for. The only pitfall to using it, though, is that the TextBox has to have the input focus in order for it to work. Call the Focus method on the TextBox before you call ScrollToCaret.

              Dave Kreskowiak Microsoft MVP - Visual Basic

              S Offline
              S Offline
              sherifffruitfly
              wrote on last edited by
              #6

              Ah! I've tried scrolltocaret before, and noticed that it did absolutely nothing. It must be the focus-thing that bit me. I'll try scrolltocaret in combination with giving the textbox the focus. Hm. It occurs to me: if the textbox MUST have focus in order for scrolltocaret to be effective, doesn't that mean it would be difficult to specialize the textbox class into a textbox + AutoScrollToBottom property class - no? Thanks a bunch everyone!

              D 1 Reply Last reply
              0
              • S sherifffruitfly

                Ah! I've tried scrolltocaret before, and noticed that it did absolutely nothing. It must be the focus-thing that bit me. I'll try scrolltocaret in combination with giving the textbox the focus. Hm. It occurs to me: if the textbox MUST have focus in order for scrolltocaret to be effective, doesn't that mean it would be difficult to specialize the textbox class into a textbox + AutoScrollToBottom property class - no? Thanks a bunch everyone!

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                It's possible to make a Textbox that autoscrolls, but you'd have to send the textbox window handle the appropriate window messages to get it to scroll. The reason why the ScrollToCaret function needs the TextBox to have the focus is because it depends on the existance of the caret. The caret doesn't exist in the TextBox until the TextBox has the focus.

                Dave Kreskowiak Microsoft MVP - Visual Basic

                S 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  It's possible to make a Textbox that autoscrolls, but you'd have to send the textbox window handle the appropriate window messages to get it to scroll. The reason why the ScrollToCaret function needs the TextBox to have the focus is because it depends on the existance of the caret. The caret doesn't exist in the TextBox until the TextBox has the focus.

                  Dave Kreskowiak Microsoft MVP - Visual Basic

                  S Offline
                  S Offline
                  sherifffruitfly
                  wrote on last edited by
                  #8

                  Hm - Looking into the prospects for an autoscroll textbox property, and I came across the dotnet scrollablecontrol class, which apparently textbox doesn't n-inherit from. http://msdn2.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx Cute little learning project: determine exactly what's involved with deriving from textbox to include an autoscroll property. Thanks!

                  D 1 Reply Last reply
                  0
                  • S sherifffruitfly

                    Hm - Looking into the prospects for an autoscroll textbox property, and I came across the dotnet scrollablecontrol class, which apparently textbox doesn't n-inherit from. http://msdn2.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx Cute little learning project: determine exactly what's involved with deriving from textbox to include an autoscroll property. Thanks!

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    ScrollableControl doesn't do what you think it does. It doesn't automatically scroll to the bottom or anything like that. It supplies scrollbars that automatically appear if the content of the child controls exceeds its boundries. There are currenly two controls and two components that are direct inheritors of this class: Panel and ToolStrip, and ContainerControl, and Design.ComponentTray.

                    Dave Kreskowiak Microsoft MVP - Visual Basic

                    S 1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      ScrollableControl doesn't do what you think it does. It doesn't automatically scroll to the bottom or anything like that. It supplies scrollbars that automatically appear if the content of the child controls exceeds its boundries. There are currenly two controls and two components that are direct inheritors of this class: Panel and ToolStrip, and ContainerControl, and Design.ComponentTray.

                      Dave Kreskowiak Microsoft MVP - Visual Basic

                      S Offline
                      S Offline
                      sherifffruitfly
                      wrote on last edited by
                      #10

                      Oh. Boy is the name "autoscroll" misleading for a property then. Thanks!

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups