Label.ImageAlign Właściwość

Definicja

Pobiera lub ustawia wyrównanie obrazu wyświetlanego w kontrolce.

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

Wartość właściwości

ContentAlignment

ContentAlignment Jedna z wartości. Wartość domyślna to ContentAlignment.MiddleCenter.

Wyjątki

Przypisana wartość nie jest jedną z ContentAlignment wartości.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć kontrolkę Label z obramowaniem trójwymiarowym i obrazem wyświetlanym przy użyciu ImageList właściwości i ImageIndex . Kontrolka ma również podpis z określonym znakiem mnemonic. Przykładowy kod używa PreferredHeight właściwości i PreferredWidth do prawidłowego rozmiaru Label kontrolki w formularzu, na którym jest wyświetlany. Ten przykład wymaga ImageList utworzenia i nazwy imageList1 oraz załadowania dwóch obrazów. Przykład wymaga również, aby kod mieścił się w formularzu, który ma System.Drawing przestrzeń nazw dodaną do jego kodu.

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

Uwagi

Ta właściwość umożliwia wyrównanie obrazu w granicach Label kontrolki w celu zapewnienia prawidłowego wyświetlania obrazu. Obraz można dodać do obiektu Label przy użyciu Image właściwości lub ImageList właściwości i ImageIndex . Obrazów wyświetlanych w kontrolce nie można rozciągnąć ani zmniejszyć w celu wypełnienia kontrolki, jeśli kontrolka jest większa lub mniejsza niż obraz.

Dotyczy

Zobacz też