65.9K
CodeProject is changing. Read more.
Home

Scrollbar in Down Side of Textbox

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.77/5 (10 votes)

Aug 3, 2009

CPOL

1 min read

viewsIcon

31430

downloadIcon

379

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