Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Scrollbar in Down Side of Textbox

0.00/5 (No votes)
3 Aug 2009 1  
Scrollbar in down side of textbox

Introduction 

This is an article to solve a simple problem. I mean to set scrollbar at the end of the text in textbox when dynamically updating the text value on that textbox.

Description

Hi all, I have come to give a very simple solution for the below question. The question is …

How to set scrollbar at the end of the text in textbox when dynamically updating the text value?

Actually I have been developing a big application. In that application, I needed to update the status of every action in my application. For the purpose of updating the status, I have used the textbox to show the status with multiline and vertical scrollbar properties have been set. But I could only see the vertical bar not going down when updating the status as shown in the below figure which is marked in red.

scrolldown1.JPG

After Googling for a few minutes, I found that we have some properties and methods in textboxes of Visual Studio - SelectionStart and ScrollToCaret methods.

By using the above property and method, I have found the solution for my question. See the below figure:

scrolldown2.JPG

Using the Code 

private void btnUpdate_Click(object sender, EventArgs e)
{
 if (!string.IsNullOrEmpty(txtStatus.Text))
 	txtStatus.Text = txtStatus.Text + Environment.NewLine;
 txtStatus.Text = txtStatus.Text + "Status Updated...";

 txtStatus.SelectionStart = txtStatus.Text.Length;
 txtStatus.ScrollToCaret();
 txtStatus.Refresh();
}

Conclusion

Hence my doubt has been solved. :)

History

  • 3rd August, 2009: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here