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

屬性值

顯示在 Image上的 Label。 預設為 null

範例

下列程式碼範例示範如何建立 Label ,然後顯示 Image 後方的 Label 。 首先,此範例會 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 不能與 和 ImageIndex 屬性同時 ImageList 使用。 Image當屬性用來顯示影像時, ImageListImageIndex 屬性會自動設定為其預設設定。

適用於

另請參閱