다음을 통해 공유


Control.Size 속성

컨트롤의 높이와 너비를 가져오거나 설정합니다.

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

구문

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

value = instance.Size

instance.Size = value
[LocalizableAttribute(true)] 
public Size Size { get; set; }
[LocalizableAttribute(true)] 
public:
property Size Size {
    Size get ();
    void set (Size value);
}
/** @property */
public Size get_Size ()

/** @property */
public void set_Size (Size value)
public function get Size () : Size

public function set Size (value : Size)

속성 값

컨트롤의 높이와 너비를 픽셀 단위로 나타내는 Size입니다.

설명

Size 클래스는 값 형식(Visual Basic의 경우 Structure, Visual C#의 경우 struct)이므로 값으로 반환됩니다. 즉, 이 속성에 액세스하면 컨트롤 크기의 복사본이 반환됩니다. 따라서 이 속성에서 반환하는 SizeWidth 또는 Height 속성을 조정해도 컨트롤의 Width 또는 Height에 영향을 주지 않습니다. 컨트롤의 Width 또는 Height를 조정하려면 컨트롤의 Width 또는 Height 속성을 설정하거나 새 SizeSize 속성을 설정해야 합니다.

참고

보다 향상된 성능을 유지하려면 컨트롤의 생성자에 해당 컨트롤의 Size를 설정하지 않아야 합니다. 더 좋은 방법은 DefaultSize 속성을 재정의하는 것입니다.

예제

다음 코드 예제에서는 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, 1.0에서 지원

참고 항목

참조

Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
SetBounds