Link to home
Start Free TrialLog in
Avatar of karen1982
karen1982

asked on

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

and how to make the textbox auto-resize if the form resize?
Avatar of cookre
cookre
Flag of United States of America image

http://www.nullfx.com/index.php?name=PNphpBB2&file=viewtopic&t=7

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.left=0
box.width=window.width/6
box.height=windowheight/4
box.top=windowheight - box.height
Avatar of TheC2
TheC2

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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassanchortopic.asp

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.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstextboxbaseclassscrolltocarettopic.asp

Hope this helps...
Avatar of 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.Focus()
        RichTextBox1.AppendText("Item" & i & vbCrLf)
    End Sub

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstextboxbaseclassappendtexttopic.asp
Avatar of karen1982

ASKER

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
For the autoscroll with ScrollToCaret() or AppendText() to work, the RTB must have the focus FIRST.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial