Label.BorderStyle 属性

获取或设置控件的边框样式。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Overridable Property BorderStyle As BorderStyle
用法
Dim instance As Label
Dim value As BorderStyle

value = instance.BorderStyle

instance.BorderStyle = value
public virtual BorderStyle BorderStyle { get; set; }
public:
virtual property BorderStyle BorderStyle {
    BorderStyle get ();
    void set (BorderStyle value);
}
/** @property */
public BorderStyle get_BorderStyle ()

/** @property */
public void set_BorderStyle (BorderStyle value)
public function get BorderStyle () : BorderStyle

public function set BorderStyle (value : BorderStyle)

属性值

BorderStyle 值之一。默认为 BorderStyle.None

异常

异常类型 条件

InvalidEnumArgumentException

分配的值不是 BorderStyle 值之一。

备注

可使用该属性为控件添加边框。该属性通常用于区别标记另一个控件的 Label 和显示应用程序中某个进程状态的 Label

示例

下面的代码示例演示如何使用 ImageListImageIndex 属性创建一个 Label 控件,该控件显示一个三维边框和一幅图像。该控件也有一个指定助记键字符的标题。此示例代码使用 PreferredHeightPreferredWidth 属性来适当地调整 Label 控件在显示它的窗体上的大小。此示例要求已创建一个名为 imageList1ImageList,并且它已加载两幅图像。此示例还要求该代码在一个窗体内,该窗体已将 System.Drawing 命名空间添加到其代码中。

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
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:
   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.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
    // Set the ImageList to use for displaying an image.
    label1.set_ImageList(imageList1);
    // Use the second image in imageList1.
    label1.set_ImageIndex(1);
    // Align the image to the top left corner.
    label1.set_ImageAlign(ContentAlignment.TopLeft);
    // Specify that the text can display mnemonic characters.
    label1.set_UseMnemonic(true);
    // Set the text of the control and specify a mnemonic character.
    label1.set_Text("First &Name:");
    /* Set the size of the control based on the PreferredHeight
       and PreferredWidth values. */
    label1.set_Size(new Size(label1.get_PreferredWidth(), 
        label1.get_PreferredHeight()));
    //...Code to add the control to the form...
} //CreateMyLabel 
public function CreateMyLabel()
{
   // Create an instance of a Label.
   var label1 : Label = 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 System.Drawing.Size (label1.PreferredWidth, label1.PreferredHeight);

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Label 类
Label 成员
System.Windows.Forms 命名空间
BorderStyle 枚举