Open In App

How to set the Alignment of the Text in the Label in C#?

In Windows Forms, Label control is used to display text on the form and it does not take part in user input or in mouse or keyboard events. You are allowed to set the alignment of the text present in the Label control using the TextAlign Property in the windows form. You can set this property using two different methods:

1. Design-Time: It is the easiest method to set the TextAlign property of the Label control using the following steps:



2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the alignment of the text in the Label control programmatically with the help of given syntax:

public virtual System.Drawing.ContentAlignment TextAlign { get; set; }

Here, the ContentAlignment specify the alignment of the text. It will throw an InvalidEnumArgumentException if the value assigned to this property does not belong to the ContentAlignment values. Following steps are used to set the TextAlign property of the Label:


Article Tags :
C#