Control.ClientSize 속성

정의

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

public:
 property System::Drawing::Size ClientSize { System::Drawing::Size get(); void set(System::Drawing::Size value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Size ClientSize { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.ClientSize : System.Drawing.Size with get, set
Public Property ClientSize As Size

속성 값

Size

컨트롤 클라이언트 영역의 크기를 나타내는 Size입니다.

특성

예제

다음 코드 예제에서는 컨트롤의 서식이 지정된 텍스트를 수용할 수 있도록 지정된 컨트롤의 크기를 조정합니다. 서식이 지정된 텍스트는 Text 컨트롤이 텍스트에 할당된 Font 속성입니다. AutoSizeControl 이 예제의 메서드에는 textPadding 컨트롤의 모든 가장자리에 적용할 안쪽 여백을 나타내는 매개 변수도 있습니다. 안쪽 여백을 동일하게 표시하려면 컨트롤이 ContentAlignment.MiddleCenter 지원하는 경우 텍스트를 값에 맞춥니다.

private:
   void AutoSizeControl( Control^ control, int textPadding )
   {
      
      // Create a Graphics object for the Control.
      Graphics^ g = control->CreateGraphics();
      
      // Get the Size needed to accommodate the formatted Text.
      System::Drawing::Size preferredSize = g->MeasureString( control->Text, control->Font ).ToSize();
      
      // Pad the text and resize the control.
      control->ClientSize = System::Drawing::Size( preferredSize.Width + (textPadding * 2), preferredSize.Height + (textPadding * 2) );
      
      // Clean up the Graphics object.
      delete g;
   }
private void AutoSizeControl(Control control, int textPadding)
{
   // Create a Graphics object for the Control.
   Graphics g = control.CreateGraphics();

   // Get the Size needed to accommodate the formatted Text.
   Size preferredSize = g.MeasureString(
      control.Text, control.Font).ToSize();

   // Pad the text and resize the control.
   control.ClientSize = new Size(
      preferredSize.Width + (textPadding * 2), 
      preferredSize.Height+(textPadding * 2) );

   // Clean up the Graphics object.
   g.Dispose();
}
Private Sub AutoSizeControl(control As Control, textPadding As Integer)
   ' Create a Graphics object for the Control.
   Dim g As Graphics = control.CreateGraphics()
   
   ' Get the Size needed to accommodate the formatted Text.
   Dim preferredSize As Size = g.MeasureString( _
     control.Text, control.Font).ToSize()
   
   ' Pad the text and resize the control.
   control.ClientSize = New Size( _
     preferredSize.Width + textPadding * 2, _
     preferredSize.Height + textPadding * 2)
   
   ' Clean up the Graphics object.
   g.Dispose()
End Sub

설명

컨트롤의 클라이언트 영역은 스크롤 막대, 테두리, 제목 표시줄 및 메뉴와 같은 비클라이언트 요소를 뺀 컨트롤의 범위입니다. 속성을 SetClientSizeCore 설정하기 위해 메서드가 호출됩니다 ClientSize . 속성이 ClientSize 메서드를 통해 set 항상 변경되지는 않으므로 속성을 설정할 때 코드가 실행되도록 메서드를 재정 SetClientSizeCoreClientSize 해야 합니다.

Size.Height 속성은 Size.Width 컨트롤의 클라이언트 영역 너비와 높이를 나타냅니다. 이 속성을 사용 하 여 컨트롤의 표면에 그리기와 같은 작업에 대 한 컨트롤의 클라이언트 영역의 크기를 가져올 수 있습니다.

컨트롤에 그리기에 대한 자세한 내용은 Windows Forms 컨트롤 렌더링을 참조하세요.

참고

애플리케이션 설정을이 속성에 바인딩할 수 없습니다. 애플리케이션 설정에 대 한 자세한 내용은 참조 하세요. 애플리케이션 설정 개요합니다.

적용 대상

추가 정보