C# | Insert Text in New Line of Multiline Text Box by Button Click

Here in this C# example, we will show how to add text in new line of Multiline text box. The text will be inserted in new line when user clicks on a button. For a demo purpose, we are taking a DateTimePicker (dateTimePicker1) control, a Button(btnAdd) control and a Multiline TextBox (txtMulti) as shown below.

C# multiline textbox example

When user clicks on ADD button, the text in dateTimePicker1 will be inserted into txtMulti. When user again clicks on ADD button after picking another date or with same date, the new date will be inserted into txtMulti.

C# multiline textbox insert line example

To achieve this, the C# code to written in click event of ADD button will be like as given below.

private void btnAdd_Click(object sender, EventArgs e)
{
 txtMulti.Text += dateTimePicker1.Text + "\r\n";
}

Leave a Reply