Label.Image Label.Image Label.Image Label.Image Property

定義

取得或設定顯示在 Label 上的影像。Gets or sets the image that is displayed on a Label.

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

屬性值

顯示在 Image上的 LabelAn Image displayed on the Label. 預設為 nullThe default is null.

範例

下列程式碼範例示範如何建立Label ,然後再Image顯示後面的LabelThe following code example demonstrates how to create a Label and then to display an Image behind the Label. 首先,此範例會建立Label ,然後Image根據磁片檔案建立。First, the example creates a Label and then creates an Image based on a disk file. 接下來, Size會初始化屬性以Image包含。Next, the Size property is initialized to contain the Image. 最後, Image屬性會初始化Image為。Finally, the Image property is initialized to the 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

備註

屬性不能與ImageListImageIndex屬性同時使用。 ImageThe Image property cannot be used at the same time as the ImageList and ImageIndex properties. 當屬性用於顯示影像時ImageList ,和ImageIndex屬性會自動設為其預設設定。 ImageWhen the Image property is used to display an image, the ImageList and ImageIndex properties are automatically set to their default settings.

適用於

另請參閱