TextBoxBase.BorderStyle 屬性

定義

取得或設定文字方塊控制項的框線樣式。

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

屬性值

BorderStyle

BorderStyle,表示文字方塊控制項的框線樣式。 預設為 Fixed3D

例外狀況

不在列舉型別 (Enumeration) 有效值範圍內的值會指派給這個屬性。

範例

下列程式碼範例會使用 TextBox 衍生類別來建立文字方塊,以使用 20 點 Arial 搭配單一框線正確顯示文字。 本範例會 PreferredHeight 使用 屬性,在字型之後判斷控制項的適當高度,並 BorderStyle 已指派給控制項。

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;
 }

備註

除了預設的三維控制項之外,您可以使用 BorderStyle 屬性來建立無框線和平面樣式控制項。

注意

衍生類別 RichTextBox 不支援 BorderStyle.FixedSingle 樣式。 此樣式會導致 BorderStyle 改用 BorderStyle.Fixed3D 樣式。

適用於

產品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7