共用方式為


Label.Image 屬性

定義

取得或設定顯示在 Label. 上的影像。

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
public System.Drawing.Image? Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

屬性值

A Image 顯示於 Label. 預設值為 null

範例

以下程式碼範例示範如何建立 ,Label然後在 後方顯示 。ImageLabel 首先,範例會建立一個 Label ,然後再根據磁碟檔案建立一個 Image 。 接著, Size 屬性初始化為包含 Image。 最後,屬性 Image 初始化為 Image

public:
   void CreateMyLabel()
   {
      // Create a new label and create a bitmap.
      Label^ label1 = gcnew Label;
      Image^ image1 = Image::FromFile( "c:\\MyImage.bmp" );

      // Set the size of the label to accommodate the bitmap size.
      label1->Size = System::Drawing::Size( image1->Width, image1->Height );

      // Initialize the label control's Image property.
      label1->Image = image1;

      // ...Code to add the control to the form...
   }
public void CreateMyLabel() 
{
 
    // Create a new label and create a bitmap.

    Label label1 = new Label();
    Image image1 = Image.FromFile("c:\\MyImage.bmp");

    // Set the size of the label to accommodate the bitmap size.

    label1.Size = new Size(image1.Width, image1.Height);

    // Initialize the label control's Image property.

    label1.Image = image1;

    // ...Code to add the control to the form...
}
Private Sub CreateMyLabel()

    ' Create a new label and bitmap.

    Dim Label1 As New Label()
    Dim Image1 As Image

    Image1 = Image.FromFile("c:\\MyImage.bmp")
   

    ' Set the size of the label to accommodate the bitmap size.

    Label1.Size = Image1.Size        

    ' Initialize the label control's Image property.

    Label1.Image = Image1

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

End Sub

備註

Image該財產不能同時ImageList使用與ImageIndex 當該 Image 屬性用於顯示影像時, ImageListImageIndex 屬性會自動設定為預設值。

適用於

另請參閱