The textbox scroll bar of the winform program remains at the bottom of the page and does not flash.

Source: Internet
Author: User

Develop winformProgramThe Textbox Control is used to display information. When the multiline attribute of textbox is changed to ture (that is, the status of multiple rows is displayed), The scrollbars attribute is changed to vertical (there are too many contents, the vertical scroll bar is displayed.

By default, when the textbox content changes, winform automatically locates the textbox scroll bar at the top of the textbox. But this is obviously not the expected result. For example, when we develop a chat program, when a message is sent, we need to drag the scroll bar to the bottom to see it, this makes people angry.

Therefore, you have to find a way to keep the scroll bar at the bottom when the textbox content is updated, so that the latest message appended to the textbox is displayed. The general method is to write the following in the textchanged event of textbox:Code:

Code

Private   Void Txt_content_textchanged ( Object Sender, eventargs E)
{
This . Txt_content.selectionstart =   This . Txt_content.text.length;
This . Txt_content.selectionlength =   0 ;
This . Txt_content.scrolltocaret ();
}

 

 

After the problem is solved, everything looks good. Later you find that the problem is solved, but each time the textbox appends the content, it will "Flash. At this time, if the program you write frequently updates the content of Textbox, such as displaying the installation process of a program, the disaster is coming. Let's take a look. The box will flash your eyes!

Delete the code above from your program! Use the following code to update the textbox content:

// Append content to textbox
Txt_content.appendtext (STR );

 

 

Run your program!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.