Scroll to the bottom of a multiline text box

TextBox Control

A TextBox control serves a dual purpose in applications, enabling the presentation and acceptance of a single line of text. This versatile control offers additional functionalities beyond the standard Windows text box, elevating its utility to greater heights. Alongside its core capabilities, the TextBox control excels in accommodating multiline editing, allowing users to interact with and modify text across multiple lines seamlessly. Furthermore, it empowers users to safeguard sensitive information with password character masking, a feature that enhances data privacy and security during input operations. The TextBox control's ability to cater to diverse text manipulation scenarios makes it an indispensable asset in creating intuitive and feature-rich user interfaces.

Multiline Text Box

How to constantly scroll to the end of text in multiline text box

A multiline text box in a graphical user interface facilitates the presentation of multiple lines of text within a single control, expanding its versatility and usability. The Multiline property plays a crucial role in this functionality, as it allows developers to determine whether the TextBox control supports multiline input or restricts it to a single line. By toggling the value of the Multiline property, developers can dynamically configure the behavior of the TextBox control, providing a flexible user interface that adapts to specific text input requirements. This powerful property empowers designers to craft intuitive and interactive forms, enhancing user experiences and enabling efficient manipulation of text across various lines within the same control.

// Set the Multiline property to true. textBox1.Multiline = true;

Scroll Bars in Multiline Text Box

autoscroll to bottom of multiline textbox

By using the ScrollBars property, developers can seamlessly augment a text box with scroll bars, both horizontally and/or vertically, thereby facilitating an intuitive user experience. This valuable addition empowers users to navigate and explore text content that surpasses the confines of the control's dimensions. With the presence of scroll bars, users can effortlessly view and interact with extended text, ensuring that no valuable information is obscured or lost. By judiciously configuring the ScrollBars property, designers can provide a responsive and user-friendly interface, allowing users to easily traverse through the text and access every bit of crucial information. The inclusion of scroll bars enhances the usability and functionality of the text box, making it a powerful tool for handling diverse text scenarios with utmost ease and convenience.

// Add vertical scroll bars to the TextBox control. textBox1.ScrollBars = ScrollBars.Vertical;

If you want both scroll bars(vertical and horizondal) you should set ..

textBox2.ScrollBars = ScrollBars.Both;
Automatically scroll to the bottom of a multiline text box

If you use TextBox.AppendText(string text), it will automatically scroll to the end of the newly appended text. It avoids the flickering scrollbar if you are calling it in a loop.


Internally, AppendText does something like this:

textBox2.Select(textBox.TextLength + 1, 0); textBox2.SelectedText = textToAppend;
C# Source Code
using System; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox2.AppendText(textBox1.Text); } private void Form1_Load(object sender, EventArgs e) { textBox2.Text = "Your text here !!"; } } }
VB.Net Source Code
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox2.AppendText(TextBox1.Text) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox2.Text = "Your text here" End Sub End Class

You can perform another way to achieve scrollbar at the end of the multiline textbox to auto scroll on the TextChanged event:

textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret(); textBox1.Refresh(); </pre> <b>VB.Net</b> <pre> textBox1.SelectionStart = textBox1.Text.Length textBox1.ScrollToCaret() textBox1.Refresh()