언어

Control.Size 속성

정의

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

public:
 property System::Drawing::Size Size { System::Drawing::Size get(); void set(System::Drawing::Size value); };
public System.Drawing.Size Size { get; set; }
member this.Size : System.Drawing.Size with get, set
Public Property Size As Size

속성 값

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

예제

다음 코드 예제에서는 폼에 Button 추가 하 고 해당 공통 속성의 일부를 설정 합니다. 이 예제에서는 폼의 오른쪽 아래 모서리에 단추를 고정하여 폼의 크기를 조정할 때 상대적 위치를 유지합니다. 그런 다음 단추를 설정하고 단추의 크기를 .와 같은 크기로 BackgroundImage조정 Image 합니다. 그런 다음 이 예제에서는 to를 TabStoptrue 설정하고 속성을 설정합니다 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

설명

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

메모

성능을 향상시키려면 해당 생성자에서 컨트롤을 Size 설정하지 마세요. 기본 설정 방법은 속성을 재정의하는 것입니다 DefaultSize .

메모

Windows Server 2003 시스템에서는 모니터의 Form 최대 픽셀 너비와 높이에 따라 크기가 제한됩니다.

적용 대상

참고 항목