TextBoxBase.BorderStyle Property

Definition

Gets or sets the border type of the text box control.

C#
public System.Windows.Forms.BorderStyle BorderStyle { get; set; }

Property Value

A BorderStyle that represents the border type of the text box control. The default is Fixed3D.

Exceptions

A value that is not within the range of valid values for the enumeration was assigned to the property.

Examples

The following code example uses TextBox, a derived class, to create a text box that can properly display text using 20-point Arial with a single border. This example uses the PreferredHeight property to determine the appropriate height of the control after the font and BorderStyle have been assigned to the control.

C#
public void CreateTextBox()
 {
    // Create an instance of the TextBox control.
    TextBox textBox1 = new TextBox();
 
    // Set the TextBox Font property to Arial 20.
    textBox1.Font = new Font ("Arial" , 20);
    // Set the BorderStyle property to FixedSingle.
    textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    // Make the height of the control equal to the preferred height.
    textBox1.Height = textBox1.PreferredHeight;
 }

Remarks

You can use the BorderStyle property to create borderless and flat style controls, in addition to the default three-dimensional control.

Note

The derived class, RichTextBox, does not support the BorderStyle.FixedSingle style. This style will cause the BorderStyle to use the BorderStyle.Fixed3D style instead.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9