다음을 통해 공유


Control.Anchor 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(True)> _
Public Overridable Property Anchor As AnchorStyles
‘사용 방법
Dim instance As Control
Dim value As AnchorStyles

value = instance.Anchor

instance.Anchor = value
[LocalizableAttribute(true)] 
public virtual AnchorStyles Anchor { get; set; }
[LocalizableAttribute(true)] 
public:
virtual property AnchorStyles Anchor {
    AnchorStyles get ();
    void set (AnchorStyles value);
}
/** @property */
public AnchorStyles get_Anchor ()

/** @property */
public void set_Anchor (AnchorStyles value)
public function get Anchor () : AnchorStyles

public function set Anchor (value : AnchorStyles)

속성 값

AnchorStyles 값의 비트 조합입니다. 기본값은 TopLeft입니다.

설명

부모 컨트롤의 크기가 조정될 때 자식 컨트롤의 크기가 자동으로 조정되는 방법을 정의하려면 Anchor 속성을 사용합니다. 컨트롤을 부모 컨트롤에 고정하면 고정된 가장자리는 부모 컨트롤의 크기가 변경되어도 부모 컨트롤의 가장자리를 기준으로 동일한 위치를 유지합니다.

컨트롤을 해당 컨테이너의 여러 가장자리에 고정할 수 있습니다. 예를 들어, Anchor 속성 값이 TopBottom로 설정된 Button이 포함된 Form이 있는 경우, FormHeight가 늘어나면 Form의 위쪽 및 아래쪽 가장자리와의 고정 거리를 유지하기 위해 Button이 늘어납니다.

참고

Anchor 속성과 Dock 속성은 함께 사용할 수 없습니다. 한 번에 하나만 설정할 수 있으며 마지막으로 설정된 것이 우선합니다.

상속자 참고 사항 파생 클래스에서 Anchor 속성을 재정의하는 경우 기본 클래스의 Anchor 속성을 사용하여 기본 구현을 확장합니다. 그렇지 않으면 모든 구현을 제공해야 합니다. Anchor 속성의 getset 접근자를 모두 재정의할 필요는 없습니다. 필요에 따라 하나의 접근자만 재정의하면 됩니다.

예제

다음 코드 예제에서는 Button을 폼에 추가하고 해당 공용 속성 중 일부를 설정합니다. 예제에서는 폼의 오른쪽 아래 모퉁이에 단추를 고정시켜 폼의 크기가 조정될 경우 상대적인 위치를 유지할 수 있도록 합니다. 다음에는 BackgroundImage를 설정하고 Image와 같은 크기로 단추의 크기를 조정합니다. 그런 다음 TabStoptrue로 설정하고 TabIndex 속성을 설정합니다. 마지막으로 단추의 Click 이벤트를 처리하는 이벤트 처리기를 추가합니다. 이 예제를 실행하려면 imageList1이라는 ImageList가 있어야 합니다.

' 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
// 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:
   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.set_Anchor(AnchorStyles.Bottom | AnchorStyles.Right);
    // Assign a background image.
    button1.set_BackgroundImage(imageList1.get_Images().get_Item(0));
    // Specify the layout style of the background image. Tile is the 
    // default.
    button1.set_BackgroundImageLayout(ImageLayout.Center);
    // Make the button the same size as the image.
    button1.set_Size(button1.get_BackgroundImage().get_Size());
    // Set the button's TabIndex and TabStop properties.
    button1.set_TabIndex(1);
    button1.set_TabStop(true);
    // Add a delegate to handle the Click event.
    button1.add_Click(new System.EventHandler(this.button1_Click));
    // Add the button to the form.
    this.get_Controls().Add(button1);
} //AddMyButton

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
AnchorStyles 열거형
Dock
Layout