AnchorStyles Перечисление
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Указывает, как элемент управления привязывается к краям контейнера.
Это перечисление поддерживает побитовую комбинацию значений его членов.
public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles =
Public Enum AnchorStyles
- Наследование
- Атрибуты
Поля
| Имя | Значение | Описание |
|---|---|---|
| None | 0 | Элемент управления не привязан к каким-либо краям контейнера. |
| Top | 1 | Элемент управления привязан к верхнему краю контейнера. |
| Bottom | 2 | Элемент управления привязан к нижнему краю контейнера. |
| Left | 4 | Элемент управления привязан к левому краю контейнера. |
| Right | 8 | Элемент управления привязан к правому краю контейнера. |
Примеры
В следующем примере добавляется форма Button и задает некоторые из его общих свойств. В примере кнопка привязывается к правому нижнему углу формы, чтобы она сохраняла относительную позицию по мере изменения размера формы. Затем он задает BackgroundImage и изменяет размер кнопки на тот же размер, что и .Image Затем в примере задается TabStop значение true и задается TabIndex свойство. Наконец, он добавляет обработчик событий для обработки Click события кнопки. В этом примере предполагается, что у вас есть именованный ImageList объект imageList1.
// Add a button to a form and set some of its common properties.
private:
void AddMyButton()
{
// Create a button and add it to the form.
Button^ button1 = gcnew Button;
// Anchor the button to the bottom right corner of the form
button1->Anchor = static_cast<AnchorStyles>(AnchorStyles::Bottom | AnchorStyles::Right);
// Assign a background image.
button1->BackgroundImage = imageList1->Images[ 0 ];
// Specify the layout style of the background image. Tile is the default.
button1->BackgroundImageLayout = ImageLayout::Center;
// Make the button the same size as the image.
button1->Size = button1->BackgroundImage->Size;
// Set the button's TabIndex and TabStop properties.
button1->TabIndex = 1;
button1->TabStop = true;
// Add a delegate to handle the Click event.
button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );
// Add the button to the form.
this->Controls->Add( button1 );
}
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
// Create a button and add it to the form.
Button button1 = new Button();
// Anchor the button to the bottom right corner of the form
button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
// Assign a background image.
button1.BackgroundImage = imageList1.Images[0];
// Specify the layout style of the background image. Tile is the default.
button1.BackgroundImageLayout = ImageLayout.Center;
// Make the button the same size as the image.
button1.Size = button1.BackgroundImage.Size;
// Set the button's TabIndex and TabStop properties.
button1.TabIndex = 1;
button1.TabStop = true;
// Add a delegate to handle the Click event.
button1.Click += new System.EventHandler(this.button1_Click);
// Add the button to the form.
this.Controls.Add(button1);
}
' Add a button to a form and set some of its common properties.
Private Sub AddMyButton()
' Create a button and add it to the form.
Dim button1 As New Button()
' Anchor the button to the bottom right corner of the form
button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
' Assign a background image.
button1.BackgroundImage = imageList1.Images(0)
' Specify the layout style of the background image. Tile is the default.
button1.BackgroundImageLayout = ImageLayout.Center
' Make the button the same size as the image.
button1.Size = button1.BackgroundImage.Size
' Set the button's TabIndex and TabStop properties.
button1.TabIndex = 1
button1.TabStop = True
' Add a delegate to handle the Click event.
AddHandler button1.Click, AddressOf Me.button1_Click
' Add the button to the form.
Me.Controls.Add(button1)
End Sub
Комментарии
При привязке элемента управления к краю контейнера расстояние между элементом управления и указанным краем остается постоянным при изменении размера контейнера. Например, если элемент управления привязан к правому краю контейнера, расстояние между правым краем элемента управления и правым краем контейнера остается постоянным при изменении размера контейнера. Элемент управления можно привязать к любой комбинации ребер элемента управления. Если элемент управления привязан к противоположным краям контейнера (например, к верхней и нижней части), он изменяет размер при изменении размера контейнера. Если для элемента управления задано значение Anchor None, элемент управления перемещается на половину расстояния, на которое изменяется размер контейнера элемента управления. Например, если Button свойство Anchor имеет значение None, а Form элемент управления расположен на 20 пикселей в любом направлении, кнопка будет перемещена в обоих направлениях на 10 пикселей.