1

I'm looking for C#.net code to scroll a richtextbox programmatically, I have searched about it but I found some examples of VB.Net but don't know how to use them. any help would be highly appreciated. Thanks in Advance :)

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
Omar Bahir
  • 1,237
  • 5
  • 20
  • 48
  • http://geekswithblogs.net/Waynerds/archive/2006/01/29/67506.aspx look at this – Kamil Budziewski Jul 04 '13 at 07:33
  • 2
    _I'm looking for C#.net code.._ This is not a good way to ask a question. Did you try anything to solve your problem? – Soner Gönül Jul 04 '13 at 07:34
  • my apology for asking for code, yes i have tried setCaret function but i didnt worked properly as i'm new to C# so i needed some help on how to solve this problem. – Omar Bahir Jul 04 '13 at 08:20

1 Answers1

2

If I properly understand, you want to scroll richtextbox to the bottom after new lines were added to this control. Just add this code to method that runs each time you add some new data:

private void AddText(string text)
{
    richTextBox1.AppendText(text + Environment.NewLine);
    richTextBox1.SelectionStart = richTextBox1.Text.Length;
    richTextBox1.ScrollToCaret();
}
odinmillion
  • 639
  • 9
  • 10
  • Thank you so much for your reply , its helpful for me , actuelly i'm making a plagiarism detector in c# , i have two richtextbox , now i want if a line matches with the second file's line , the second richtextbox should auto scrolled and take the matched line in front of first textbox's matched line. just want to know if there any function which can scroll through specific lines ??? – Omar Bahir Jul 04 '13 at 08:24
  • 1
    Please try to use Find method: [link](http://msdn.microsoft.com/en-us/library/hfcsf75k.aspx). You can search and scroll in this way: [link](http://stackoverflow.com/a/4323299/1554861). Was it helpful? – odinmillion Jul 04 '13 at 08:36
  • Thanks alot :) very closer to what i was actually looking for :) Thanks to all of you for helping :) – Omar Bahir Jul 04 '13 at 08:43
  • Substring searching is a very deep and interesting theme) Take a look at this for example: [link](http://stackoverflow.com/questions/3183582/what-is-the-fastest-substring-search-algorithm) – odinmillion Jul 04 '13 at 08:48