다음을 통해 공유


LayoutEventArgs 클래스

정의

Layout 이벤트에 대한 데이터를 제공합니다. 이 클래스는 상속될 수 없습니다.

public ref class LayoutEventArgs sealed : EventArgs
public sealed class LayoutEventArgs : EventArgs
type LayoutEventArgs = class
    inherit EventArgs
Public NotInheritable Class LayoutEventArgs
Inherits EventArgs
상속
LayoutEventArgs

예제

다음 코드 예제에서는 및 속성을 인수로 LayoutEventHandler 사용하여 AffectedPropertyAffectedControl Windows 폼과 해당 컨트롤의 크기를 Windows 폼과 컨트롤 모두에 대한 다양한 속성 변경 내용으로 조정합니다.

public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::TextBox^ textBox1;
   System::Windows::Forms::Label ^ label1;
   System::Windows::Forms::Button^ layoutButton;
   System::ComponentModel::Container^ components;

public:
   Form1()
   {
      InitializeComponent();
   }

protected:
   ~Form1()
   {
      if ( components != nullptr )
      {
         delete components;
      }
   }

private:
   void InitializeComponent()
   {
      this->layoutButton = gcnew System::Windows::Forms::Button;
      this->textBox1 = gcnew System::Windows::Forms::TextBox;
      this->label1 = gcnew System::Windows::Forms::Label;
      this->SuspendLayout();

      // 
      // layoutButton
      // 
      this->layoutButton->Anchor = System::Windows::Forms::AnchorStyles::Bottom;
      this->layoutButton->Location = System::Drawing::Point( 72, 88 );
      this->layoutButton->Name = "layoutButton";
      this->layoutButton->Size = System::Drawing::Size( 150, 23 );
      this->layoutButton->TabIndex = 0;
      this->layoutButton->Text = "Hello";

      // 
      // textBox1
      // 
      this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left | System::Windows::Forms::AnchorStyles::Right);
      this->textBox1->Location = System::Drawing::Point( 24, 40 );
      this->textBox1->Name = "textBox1";
      this->textBox1->Size = System::Drawing::Size( 248, 20 );
      this->textBox1->TabIndex = 1;
      this->textBox1->Text = "Hello";
      this->textBox1->TextChanged += gcnew System::EventHandler( this, &Form1::textBox1_TextChanged );

      // 
      // label1
      // 
      this->label1->Location = System::Drawing::Point( 24, 16 );
      this->label1->Name = "label1";
      this->label1->TabIndex = 2;
      this->label1->Text = "Button's Text:";

      // 
      // Form1
      // 
      this->ClientSize = System::Drawing::Size( 292, 129 );
      array<System::Windows::Forms::Control^>^temp0 = {this->label1,this->textBox1,this->layoutButton};
      this->Controls->AddRange( temp0 );
      this->Name = "Form1";
      this->Text = "Layout Sample";
      this->Layout += gcnew System::Windows::Forms::LayoutEventHandler( this, &Form1::Form1_Layout );
      this->ResumeLayout( false );
   }

   // This method ensures that the form's width is the preferred size of 300 pixels
   // or the size of the button plus 50 pixels, whichever amount is less.
   void Form1_Layout( Object^ /*sender*/, System::Windows::Forms::LayoutEventArgs^ e )
   {
      // This event is raised once at startup with the AffectedControl
      // and AffectedProperty properties on the LayoutEventArgs as null. 
      // The event provides size preferences for that case.
      if ( (e->AffectedControl != nullptr) && (e->AffectedProperty != nullptr) )
      {
         // Ensure that the affected property is the Bounds property
         // of the form.
         if ( e->AffectedProperty->ToString()->Equals( "Bounds" ) )
         {
            // If layoutButton's width plus a padding of 50 pixels is greater than the preferred 
            // size of 300 pixels, increase the form's width.
            if ( (this->layoutButton->Width + 50) > 300 )
            {
               this->Width = this->layoutButton->Width + 50;
            }
            // If not, keep the form's width at 300 pixels.
            else
            {
               this->Width = 300;
            }

            // Center layoutButton on the form.
            this->layoutButton->Left = (this->ClientSize.Width - this->layoutButton->Width) / 2;
         }
      }
   }

   // This method sets the Text property of layoutButton to the Text property
   // of textBox1.  If the new text plus a padding of 20 pixels is larger than 
   // the preferred size of 150 pixels, increase layoutButton's Width property.
   void textBox1_TextChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Set the Text property of layoutButton.
      this->layoutButton->Text = this->textBox1->Text;

      // Get the width of the text using the proper font.
      int textWidth = (int)this->CreateGraphics()->MeasureString( layoutButton->Text, layoutButton->Font ).Width;

      // If the width of the text plus a padding of 20 pixels is greater than the preferred size of
      // 150 pixels, increase layoutButton's width.
      if ( (textWidth + 20) > 150 )
      {
         // Setting the size property on any control raises 
         // the Layout event for its container.
         this->layoutButton->Width = textWidth + 20;
      }
      // If not, keep layoutButton's width at 150 pixels.
      else
      {
         this->layoutButton->Width = 150;
      }
   }
};

[STAThread]
int main()
{
   Application::Run( gcnew Form1 );
}
public class Form1 : System.Windows.Forms.Form
{
   private System.Windows.Forms.TextBox textBox1;
   private System.Windows.Forms.Label label1;
   private System.Windows.Forms.Button layoutButton;
   private System.ComponentModel.Container components = null;

   public Form1()
   {
      InitializeComponent();
   }

   protected override void Dispose( bool disposing )
   {
      if( disposing )
      {
         if (components != null) 
         {
            components.Dispose();
         }
      }
      base.Dispose( disposing );
   }

   private void InitializeComponent()
   {
      this.layoutButton = new System.Windows.Forms.Button();
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.label1 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // layoutButton
      // 
      this.layoutButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
      this.layoutButton.Location = new System.Drawing.Point(72, 88);
      this.layoutButton.Name = "layoutButton";
      this.layoutButton.Size = new System.Drawing.Size(150, 23);
      this.layoutButton.TabIndex = 0;
      this.layoutButton.Text = "Hello";
      // 
      // textBox1
      // 
      this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
         | System.Windows.Forms.AnchorStyles.Right);
      this.textBox1.Location = new System.Drawing.Point(24, 40);
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(248, 20);
      this.textBox1.TabIndex = 1;
      this.textBox1.Text = "Hello";
      this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(24, 16);
      this.label1.Name = "label1";
      this.label1.TabIndex = 2;
      this.label1.Text = "Button\'s Text:";
      // 
      // Form1
      // 
      this.ClientSize = new System.Drawing.Size(292, 129);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                   this.label1,
                                                                   this.textBox1,
                                                                   this.layoutButton});
      this.Name = "Form1";
      this.Text = "Layout Sample";
      this.Layout += new System.Windows.Forms.LayoutEventHandler(this.Form1_Layout);
      this.ResumeLayout(false);
   }

   [STAThread]
   static void Main() 
   {
      Application.Run(new Form1());
   }
   
   // This method ensures that the form's width is the preferred size of 300 pixels
   // or the size of the button plus 50 pixels, whichever amount is less.
   private void Form1_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
   {
      // This event is raised once at startup with the AffectedControl
      // and AffectedProperty properties on the LayoutEventArgs as null. 
      // The event provides size preferences for that case.
      if ((e.AffectedControl != null) && (e.AffectedProperty != null))
      {
         // Ensure that the affected property is the Bounds property
         // of the form.
         if (e.AffectedProperty.ToString() == "Bounds") 
         {
            // If layoutButton's width plus a padding of 50 pixels is greater than the preferred 
            // size of 300 pixels, increase the form's width.
            if ((this.layoutButton.Width + 50) > 300) 
            {
               this.Width = this.layoutButton.Width + 50;
            }
               // If not, keep the form's width at 300 pixels.
            else 
            {
               this.Width = 300;
            }

            // Center layoutButton on the form.
            this.layoutButton.Left = (this.ClientSize.Width - this.layoutButton.Width) / 2;
         }
      }
   }

   // This method sets the Text property of layoutButton to the Text property
   // of textBox1.  If the new text plus a padding of 20 pixels is larger than 
   // the preferred size of 150 pixels, increase layoutButton's Width property.
   private void textBox1_TextChanged(object sender, System.EventArgs e)
   {
      // Set the Text property of layoutButton.
      this.layoutButton.Text = this.textBox1.Text;
      // Get the width of the text using the proper font.
      int textWidth = (int)this.CreateGraphics().MeasureString(layoutButton.Text, layoutButton.Font).Width;

      // If the width of the text plus a padding of 20 pixels is greater than the preferred size of
      // 150 pixels, increase layoutButton's width.
      if ((textWidth + 20) > 150)
      {
         // Setting the size property on any control raises 
         // the Layout event for its container.
         this.layoutButton.Width = textWidth + 20;
      }
         // If not, keep layoutButton's width at 150 pixels.
      else 
      {
         this.layoutButton.Width = 150;
      }
   }
}
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private WithEvents textBox1 As System.Windows.Forms.TextBox
    Private label1 As System.Windows.Forms.Label
    Private layoutButton As System.Windows.Forms.Button
    Private components As System.ComponentModel.Container = Nothing


    Public Sub New()
        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If (components IsNot Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private Sub InitializeComponent()
        Me.layoutButton = New System.Windows.Forms.Button()
        Me.textBox1 = New System.Windows.Forms.TextBox()
        Me.label1 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        ' 
        ' layoutButton
        ' 
        Me.layoutButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom
        Me.layoutButton.Location = New System.Drawing.Point(72, 88)
        Me.layoutButton.Name = "layoutButton"
        Me.layoutButton.Size = New System.Drawing.Size(150, 23)
        Me.layoutButton.TabIndex = 0
        Me.layoutButton.Text = "Hello"
        ' 
        ' textBox1
        ' 
        Me.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right
        Me.textBox1.Location = New System.Drawing.Point(24, 40)
        Me.textBox1.Name = "textBox1"
        Me.textBox1.Size = New System.Drawing.Size(248, 20)
        Me.textBox1.TabIndex = 1
        Me.textBox1.Text = "Hello"
        ' 
        ' label1
        ' 
        Me.label1.Location = New System.Drawing.Point(24, 16)
        Me.label1.Name = "label1"
        Me.label1.TabIndex = 2
        Me.label1.Text = "Button's Text:"
        ' 
        ' Form1
        ' 
        Me.ClientSize = New System.Drawing.Size(292, 129)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label1, Me.textBox1, Me.layoutButton})
        Me.Name = "Form1"
        Me.Text = "Layout Sample"
        Me.ResumeLayout(False)
    End Sub

   ' This method ensures that the form's width is the preferred size of 300 pixels
   ' or the size of the button plus 50 pixels, whichever amount is less.
    Private Sub Form1_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
      ' This event is raised once at startup with the AffectedControl
      ' and AffectedProperty properties on the LayoutEventArgs as null. 
      ' The event provides size preferences for that case.
        If (e.AffectedControl IsNot Nothing) And (e.AffectedProperty IsNot Nothing) Then
            ' Ensure that the affected property is the Bounds property
            ' of the form.
            If e.AffectedProperty.ToString() = "Bounds" Then
             ' If layoutButton's width plus a padding of 50 pixels is greater than the preferred 
             ' size of 300 pixels, increase the form's width.
                If Me.layoutButton.Width + 50 > 300 Then
                    Me.Width = Me.layoutButton.Width + 50
                    ' If not, keep the form's width at 300 pixels.
                Else
                    Me.Width = 300
                End If

                ' Center layoutButton on the form.
                Me.layoutButton.Left = (Me.ClientSize.Width - Me.layoutButton.Width) / 2
            End If
        End If
    End Sub

    ' This method sets the Text property of layoutButton to the Text property
    ' of textBox1.  If the new text plus a padding of 20 pixels is larger than 
    ' the preferred size of 150 pixels, increase layoutButton's Width property.
    Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
        ' Set the Text property of layoutButton.
        Me.layoutButton.Text = Me.textBox1.Text
        ' Get the width of the text using the proper font.
        Dim textWidth As Integer = CInt(Me.CreateGraphics().MeasureString(layoutButton.Text, layoutButton.Font).Width)

        ' If the width of the text plus a padding of 20 pixels is greater than the preferred size of
        ' 150 pixels, increase layoutButton's width.
        If textWidth + 20 > 150 Then
            ' Setting the size property on any control raises 
            ' the Layout event for its container.
            Me.layoutButton.Width = textWidth + 20
            ' If not, keep layoutButton's width at 150 pixels.
        Else
            Me.layoutButton.Width = 150
        End If
    End Sub
End Class

설명

자식 컨트롤의 크기 조정, 표시 또는 숨기기, 자식 컨트롤 추가 또는 제거와 같은 컨트롤을 변경하면 컨트롤이 자식 컨트롤을 레이아웃해야 합니다. 는 LayoutEventArgs 변경된 자식 컨트롤과 영향을 받는 속성을 지정합니다. 예를 들어 컨트롤이 마지막 레이아웃 작업 이후 표시되면 속성이 Visible 영향을 받습니다.

AffectedControl 메서드가 호출될 때 값이 제공되지 않은 경우 및 AffectedProperty 속성이 로 PerformLayout 설정 null 됩니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

생성자

LayoutEventArgs(Control, String)

지정된 컨트롤 및 영향 받는 속성을 사용하여 LayoutEventArgs 클래스의 새 인스턴스를 초기화합니다.

LayoutEventArgs(IComponent, String)

지정된 구성 요소 및 영향 받는 속성을 사용하여 LayoutEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

AffectedComponent

레이아웃 변경의 영향을 받는 Component를 가져옵니다.

AffectedControl

변경의 영향을 받는 자식 컨트롤을 가져옵니다.

AffectedProperty

변경의 영향을 받는 속성을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보