Label.ImageAlign Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit l’alignement d’une image affichée dans le contrôle.
public:
property System::Drawing::ContentAlignment ImageAlign { System::Drawing::ContentAlignment get(); void set(System::Drawing::ContentAlignment value); };
public System.Drawing.ContentAlignment ImageAlign { get; set; }
member this.ImageAlign : System.Drawing.ContentAlignment with get, set
Public Property ImageAlign As ContentAlignment
Valeur de propriété
Une des ContentAlignment valeurs. La valeur par défaut est ContentAlignment.MiddleCenter.
Exceptions
La valeur affectée n’est pas l’une ContentAlignment des valeurs.
Exemples
L’exemple de code suivant montre comment créer un Label contrôle qui a une bordure tridimensionnelle et une image affichée à l’aide des propriétés et ImageIndex des ImageList propriétés. Le contrôle a également une légende avec un caractère mnemonique spécifié. L’exemple de code utilise les propriétés et PreferredWidth les PreferredHeight propriétés pour dimensionner correctement le Label contrôle sur le formulaire sur lequel il est affiché. Cet exemple nécessite qu’une ImageList image a été créée et nommée imageList1 et qu’elle ait chargé deux images. L’exemple nécessite également que le code se trouve dans un formulaire dont l’espace System.Drawing de noms est ajouté à son code.
public:
void CreateMyLabel()
{
// Create an instance of a Label.
Label^ label1 = gcnew Label;
// Set the border to a three-dimensional border.
label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
// Set the ImageList to use for displaying an image.
label1->ImageList = imageList1;
// Use the second image in imageList1.
label1->ImageIndex = 1;
// Align the image to the top left corner.
label1->ImageAlign = ContentAlignment::TopLeft;
// Specify that the text can display mnemonic characters.
label1->UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1->Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
//...Code to add the control to the form...
}
public void CreateMyLabel()
{
// Create an instance of a Label.
Label label1 = new Label();
// Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
// Set the ImageList to use for displaying an image.
label1.ImageList = imageList1;
// Use the second image in imageList1.
label1.ImageIndex = 1;
// Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft;
// Specify that the text can display mnemonic characters.
label1.UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);
//...Code to add the control to the form...
}
Public Sub CreateMyLabel()
' Create an instance of a Label.
Dim label1 As New Label()
' Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Set the ImageList to use for displaying an image.
label1.ImageList = imageList1
' Use the second image in imageList1.
label1.ImageIndex = 1
' Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft
' Specify that the text can display mnemonic characters.
label1.UseMnemonic = True
' Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:"
' Set the size of the control based on the PreferredHeight and PreferredWidth values.
label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)
'...Code to add the control to the form...
End Sub
Remarques
Cette propriété vous permet d’aligner une image dans les limites du Label contrôle pour vous assurer que l’image est correctement affichée. Vous pouvez ajouter une image à une Label utilisation de la Image propriété ou des ImageIndexImageList propriétés. Les images affichées dans le contrôle ne peuvent pas être étirées ou réduites pour remplir le contrôle si le contrôle est plus grand ou plus petit que l’image.