TextBoxBase.BorderStyle 属性

定义

获取或设置文本框控件的边框类型。Gets or sets the border type of the text box control.

public:
 property System::Windows::Forms::BorderStyle BorderStyle { System::Windows::Forms::BorderStyle get(); void set(System::Windows::Forms::BorderStyle value); };
public System.Windows.Forms.BorderStyle BorderStyle { get; set; }
member this.BorderStyle : System.Windows.Forms.BorderStyle with get, set
Public Property BorderStyle As BorderStyle

属性值

表示文本框控件边框类型的 BorderStyleA BorderStyle that represents the border type of the text box control. 默认值为 Fixed3DThe default is Fixed3D.

异常

分配给该属性的值不在该枚举的有效值范围内。A value that is not within the range of valid values for the enumeration was assigned to the property.

示例

下面的代码示例使用TextBox派生类来创建一个文本框,该文本框可使用带有单一边框的20点 Arial 来正确显示文本。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. 此示例使用PreferredHeight属性来确定控件在字体后的适当高度,并BorderStyle将其分配给控件。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.

public:
   void CreateTextBox()
   {
      // Create an instance of the TextBox control.
      TextBox^ textBox1 = gcnew TextBox;
      
      // Set the TextBox Font property to Arial 20.
      textBox1->Font = gcnew System::Drawing::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;
   }
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;
 }

Public Sub CreateTextBox()
    ' Create an instance of the TextBox control.
    Dim textBox1 As 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
End Sub

注解

除了默认的三维BorderStyle控件外,还可以使用属性创建无边框和平面样式的控件。You can use the BorderStyle property to create borderless and flat style controls, in addition to the default three-dimensional control.

备注

派生类RichTextBoxBorderStyle.FixedSingle支持样式。The derived class, RichTextBox, does not support the BorderStyle.FixedSingle style. 此样式将导致BorderStyle改为BorderStyle.Fixed3D使用样式。This style will cause the BorderStyle to use the BorderStyle.Fixed3D style instead.

适用于