• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

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

and how to make the textbox auto-resize if the form resize?
1 Solution

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.
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.top=windowheight - box.height
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...
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Mike TomlinsonMiddle School Assistant TeacherCommented:
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

karen1982Author Commented:
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
Mike TomlinsonMiddle School Assistant TeacherCommented:
For the autoscroll with ScrollToCaret() or AppendText() to work, the RTB must have the focus FIRST.
Mike TomlinsonMiddle School Assistant TeacherCommented:

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now