Add a New Line and Start a Paragraph - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

Adding new lines in visual basic is a straight forward method. It can achieved using the following method:

Using Environment.NewLine

The first part of the code is using the Environment.NewLine method to add a new line

Focusing the textbox

The second part is focusing the textbox specially if you use a button to add the new paragraph

Removing the selection highlight

When focusing the textbox, all text will be highlighted, therefore we will remove that by setting the SelectionStart to the length of the text

The Code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        TextBox1.Text &= Environment.NewLine
        TextBox1.SelectionStart = TextBox1.Text.Length
End Sub

Share This

Home | About | Contact | Privacy Policy

Copyright 2017 - All Rights Reserved.