richtextbox c# auto show
So heres my 1st question,
i have a rich text box control in c#, problem is, i have to scroll down to see the latest stream(im using filesystemwatcher). now, how can i make the richtextbox to display the last line so that 开发者_如何学Ci do not have to scroll down. thanks. (in other words, i want richtextbox to show the latest text)
Also 2nd question, how do i create a file using an object and close the stream object. coz i want to overwrite an existing file.
something like this could you do for qouestion #1
txtBox.ScrollToLine(txtBox.LineCount - 1);
now you will always see the last line
edit: just saw it's a rich text box. Just do this:
txtBox.SelectionLength = 0;
txtBox.SelectionStart = txtBox.Text.Length;
txtBox.ScrollToCaret();
if you want to overwrite a file just do this:
FileStream fileStream = new FileStream(@"c:\file.txt", FileMode.Create);
Try with:
rtb.SelectionLength = 0;
rtb.SelectionStart = rtb.Text.Length;
rtb.ScrollToCaret();
精彩评论