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!