Click here to Skip to main content
15,898,035 members
Articles / Desktop Programming / Windows Forms

Scrollbar in Down Side of Textbox

Rate me:
Please Sign up or sign in to vote.
2.77/5 (10 votes)
3 Aug 2009CPOL1 min read 30.9K   374   14   7
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 

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.

Blog:

visit my blog

Interests:

I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.

Comments and Discussions

 
GeneralAnother Solution Pin
Cihan Topçu4-Aug-09 2:58
Cihan Topçu4-Aug-09 2:58 
GeneralMy vote of 1 Pin
Neni-san4-Aug-09 0:09
Neni-san4-Aug-09 0:09 
GeneralMy vote of 1 Pin
patrak3-Aug-09 21:50
patrak3-Aug-09 21:50 
GeneralMy vote of 2 Pin
Ashutosh Bhawasinka3-Aug-09 6:06
Ashutosh Bhawasinka3-Aug-09 6:06 
GeneralMy vote of 3 Pin
alrsds23-Sep-09 16:45
alrsds23-Sep-09 16:45 
GeneralMy vote of 1 Pin
Jon Clare3-Aug-09 5:07
Jon Clare3-Aug-09 5:07 
GeneralMy vote of 1 Pin
Michael E. Jones3-Aug-09 4:24
Michael E. Jones3-Aug-09 4:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.