Label.BorderStyle Label.BorderStyle Label.BorderStyle Label.BorderStyle Property

定義

取得或設定控制項的框線樣式。Gets or sets the border style for the control.

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

屬性值

其中一個 BorderStyle 值。One of the BorderStyle values. 預設為 BorderStyle.NoneThe default is BorderStyle.None.

例外狀況

所指派的值不是其中一個 BorderStyle 值。The value assigned is not one of the BorderStyle values.

範例

下列程式碼範例示範如何建立Label具有3d 框線的控制項,以及ImageList使用和ImageIndex屬性顯示的影像。The following code example demonstrates how to create a Label control that has a three-dimensional border and an image displayed using the ImageList and ImageIndex properties. 控制項也有一個標題,其中指定了助憶鍵字元。The control also has a caption with a mnemonic character specified. 範例程式碼會使用PreferredHeightPreferredWidth Label屬性,適當地將控制項的大小調整為顯示的表單上。The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. 這個範例要求ImageList已建立並命名為 imageList1,且已載入兩個映射。This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. 此範例也會要求程式碼必須在將System.Drawing命名空間加入其程式碼的表單中。The example also requires that the code is within a form that has the System.Drawing namespace added to its code.

public:
   void CreateMyLabel()
   {
      // Create an instance of a Label.
      Label^ label1 = gcnew Label;
      
      // Set the border to a three-dimensional border.
      label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
      // Set the ImageList to use for displaying an image.
      label1->ImageList = imageList1;
      // Use the second image in imageList1.
      label1->ImageIndex = 1;
      // Align the image to the top left corner.
      label1->ImageAlign = ContentAlignment::TopLeft;
      
      // Specify that the text can display mnemonic characters.
      label1->UseMnemonic = true;
      // Set the text of the control and specify a mnemonic character.
      label1->Text = "First &Name:";
      
      /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
      label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
      
      //...Code to add the control to the form...
   }
public void CreateMyLabel()
{
   // Create an instance of a Label.
   Label label1 = new Label();

   // Set the border to a three-dimensional border.
   label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
   // Set the ImageList to use for displaying an image.
   label1.ImageList = imageList1;
   // Use the second image in imageList1.
   label1.ImageIndex = 1;
   // Align the image to the top left corner.
   label1.ImageAlign = ContentAlignment.TopLeft;

   // Specify that the text can display mnemonic characters.
   label1.UseMnemonic = true;
   // Set the text of the control and specify a mnemonic character.
   label1.Text = "First &Name:";
   
   /* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
   label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);

   //...Code to add the control to the form...
}

Public Sub CreateMyLabel()
    ' Create an instance of a Label.
    Dim label1 As New Label()
       
    ' Set the border to a three-dimensional border.
    label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    ' Set the ImageList to use for displaying an image.
    label1.ImageList = imageList1
    ' Use the second image in imageList1.
    label1.ImageIndex = 1
    ' Align the image to the top left corner.
    label1.ImageAlign = ContentAlignment.TopLeft
     
    ' Specify that the text can display mnemonic characters.
    label1.UseMnemonic = True
    ' Set the text of the control and specify a mnemonic character.
    label1.Text = "First &Name:"
       
    ' Set the size of the control based on the PreferredHeight and PreferredWidth values. 
    label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)

    '...Code to add the control to the form...
End Sub

備註

您可以使用這個屬性,將框線新增至控制項。You can use this property to add a border to the control. 這個屬性通常是用來區別Label標記另一個控制項Label的,它會顯示應用程式中進程的狀態。This property is typically used to differentiate a Label that labels another control from a Label that displays the status of a process in an application.

適用於

另請參閱