Label.ImageAlign Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает или задает выравнивание изображения, отображаемого в элементе управления.
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
Значение свойства
Одно из значений ContentAlignment . Значение по умолчанию — ContentAlignment.MiddleCenter.
Исключения
Присвоенное значение не является одним из значений ContentAlignment .
Примеры
В следующем примере кода показано, как создать Label элемент управления с трехмерной границей и изображением, отображаемым с помощью ImageList и ImageIndex свойства. Элемент управления также содержит заголовок с заданным символом mnemonic. В примере кода используются PreferredHeight свойства и PreferredWidth свойства для правильного Label размера элемента управления в форме, на которой она отображается. В этом примере требуется, чтобы ImageList созданный и именованный imageList1 был создан и загружен два образа. В примере также требуется, чтобы код находится в форме с пространством имен, System.Drawing добавленным в его код.
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
Комментарии
Это свойство позволяет выровнять изображение в границах Label элемента управления, чтобы убедиться, что изображение отображается правильно. Вы можете добавить изображение в LabelImage свойство или ImageListImageIndex свойства. Изображения, отображаемые в элементе управления, нельзя растянуть или уменьшить, чтобы заполнить элемент управления, если элемент управления больше или меньше изображения.