C#witn window application, how to make rich text box auto scroll???

Posted on 2005-05-05
Last Modified: 2008-01-09
and how to make the textbox auto-resize if the form resize?
Question by:karen1982
    LVL 23

    Expert Comment


    I would think you'ld have to do the resize yourself, i.e., adjust top, left, width, and height dynamicaly in response to a window re-size to match your preferred proportions and percentage of its footprint within the window.
    LVL 23

    Expert Comment

    For example, let's say you want the box to be in the bottom left corner and have a height of 1/4 of the window's height and a width of 1/6 of the windows width, then

    box.height=windowheight/4 - box.height
    LVL 2

    Expert Comment

    For resize, you can set the anchors of the text box.
    What you do is place the text box where you want on the form, and then set anchors in the relevant sides. Any side you set an anchor on will stay at it's current distance from that side on the form. For example, if you want it to resize along with the form, you'd have to set all the anchors.
    It's a bit hard to explain, so I suggest you just try it, you can find it in the Properties pane when you select the text box in design view. After setting the anchors try to resize the form and see what happens.
    I should say that anchors generally work, but I have encountered times when they can be quite a pain, but it's worth a try.
    You can find more information here:

    About the autoscroll, I didn't quite understand what you ment...
    I can tell you that if you want the text box to scroll somewhere you can set the caret at this position and then call the ScrollToCaret method.

    Hope this helps...
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    If you are adding lines to the end of a RTB and want it to autoscroll to that new line then give the RTB focus and use the AppendText() method.  Here is an example in VB.Net:

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Static i As Integer
            i = i + 1
            RichTextBox1.AppendText("Item" & i & vbCrLf)
        End Sub

    Author Comment

    thanks for all of you guys reply,,
    i tried to use the client size to do the resize, but didn't work out well,
    and the scrolltocaret() didn't work well too,

    what i am tring to do is, write an irc client, but when the messages come and i display that to the richtext box, but the text box doesn't auto scroll,, kind of pain to do that by hand
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    For the autoscroll with ScrollToCaret() or AppendText() to work, the RTB must have the focus FIRST.
    LVL 85

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    mirrorEnds challenge 6 64
    sumNumber challenge 16 78
    EvenOdd challenge 10 67
    copyEvens challenge 6 46
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    This is about my first experience with programming Arduino.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now