다음을 통해 공유


Control.Anchor 속성

정의

컨트롤이 바인딩되는 컨테이너의 가장자리를 가져오거나 설정하며 컨트롤의 크기를 부모로 조정하는 방법을 결정합니다.

public:
 virtual property System::Windows::Forms::AnchorStyles Anchor { System::Windows::Forms::AnchorStyles get(); void set(System::Windows::Forms::AnchorStyles value); };
public virtual System.Windows.Forms.AnchorStyles Anchor { get; set; }
member this.Anchor : System.Windows.Forms.AnchorStyles with get, set
Public Overridable Property Anchor As AnchorStyles

속성 값

값의 비트 조합입니다 AnchorStyles . 기본값은 Top and .Left

예제

다음 코드 예제에서는 폼에 Button 추가 하 고 해당 공통 속성의 일부를 설정 합니다. 이 예제에서는 폼의 오른쪽 아래 모서리에 단추를 고정하여 폼의 크기를 조정할 때 상대적 위치를 유지합니다. 그런 다음 단추를 설정하고 단추의 크기를 .와 같은 크기로 Image조정 BackgroundImage 합니다. 그런 다음 이 예제에서는 to를 TabStoptrue 설정하고 속성을 설정합니다 TabIndex . 마지막으로 단추의 이벤트를 처리하는 Click 이벤트 처리기를 추가합니다. 이 예제에서는 명명imageList1ImageList 이름이 있어야 합니다.

   // 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 크기가 조정될 때 컨트롤의 크기를 자동으로 조정하는 방법을 정의하려면 이 속성을 사용합니다. 컨트롤을 부모 컨트롤에 고정하면 부모 컨트롤의 크기를 조정할 때 고정된 가장자리가 부모 컨트롤의 가장자리를 기준으로 동일한 위치에 유지됩니다.

컨트롤을 컨테이너의 하나 이상의 가장자리에 고정할 수 있습니다. 예를 들어 속성 값이 설정된 값이 ButtonAnchor 있는 경우 Form 위쪽 및 ButtonBottom아래쪽 가장자리 FormHeightForm 까지의 고정된 거리를 유지하기 위해 확장됩니다.Top

메모

Anchor 속성은 Dock 상호 배타적입니다. 한 번에 하나만 설정할 수 있으며 마지막 집합이 우선합니다.

상속자 참고

파생 클래스에서 Anchor 속성을 재정의하는 경우 기본 클래스의 Anchor 속성을 사용하여 기본 구현을 확장합니다. 그렇지 않으면 모든 구현을 제공해야 합니다. 속성의 접근자와 set 접근자를 모두 get 재정의할 필요는 없습니다. 필요한 경우 하나만 재정의 Anchor 할 수 있습니다.

적용 대상

추가 정보