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

Свойство 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 нельзя использовать одновременно с ImageList свойствами и ImageIndex свойствами. Image Если свойство используется для отображения изображения, ImageList параметры и ImageIndex свойства автоматически задаются в качестве параметров по умолчанию.

Применяется к

См. также раздел