Label.Image Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece la imagen que se muestra en un control 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
Valor de propiedad
Image que se muestra en Label. De manera predeterminada, es null.
Ejemplos
En el ejemplo de código siguiente se muestra cómo crear y Label , a continuación, mostrar un Image elemento detrás de Label. En primer lugar, el ejemplo crea y Label , a continuación, crea un objeto Image basado en un archivo de disco. A continuación, la Size propiedad se inicializa para contener .Image Por último, la Image propiedad se inicializa en .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
Comentarios
La Image propiedad no se puede usar al mismo tiempo que las ImageList propiedades y ImageIndex . Cuando la Image propiedad se usa para mostrar una imagen, las ImageList propiedades y ImageIndex se establecen automáticamente en su configuración predeterminada.