Label.ImageAlign Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft die Ausrichtung eines Bilds ab, das im Steuerelement angezeigt wird, oder legt diese fest.
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
Eigenschaftswert
Einer der ContentAlignment Werte. Der Standardwert lautet ContentAlignment.MiddleCenter.
Ausnahmen
Der zugewiesene Wert ist keiner der ContentAlignment Werte.
Beispiele
Im folgenden Codebeispiel wird das Erstellen eines Steuerelements mit einem Label dreidimensionalen Rahmen und einem Bild veranschaulicht, das mit den ImageList Eigenschaften ImageIndex angezeigt wird. Das Steuerelement verfügt auch über eine Beschriftung mit einem angegebenen Mnemonic-Zeichen. Der Beispielcode verwendet die Eigenschaften und PreferredWidth die PreferredHeight richtige Größe des Label Steuerelements im Formular, auf dem es angezeigt wird. In diesem Beispiel ist erforderlich, dass ein ImageList ImageList1 erstellt und mit dem Namen "imageList1" erstellt wurde und zwei Bilder geladen hat. Das Beispiel erfordert außerdem, dass sich der Code in einem Formular befindet, das dem Code den System.Drawing Namespace hinzugefügt hat.
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
Hinweise
Mit dieser Eigenschaft können Sie ein Bild innerhalb der Grenzen des Label Steuerelements ausrichten, um sicherzustellen, dass das Bild ordnungsgemäß angezeigt wird. Sie können einer Eigenschaft oder ImageListImageIndex den Image Eigenschaften ein Label Bild hinzufügen. Bilder, die im Steuerelement angezeigt werden, können nicht gestreckt oder verkleinert werden, um das Steuerelement auszufüllen, wenn das Steuerelement größer oder kleiner als das Bild ist.