Control.PerformLayout Control.PerformLayout Control.PerformLayout Control.PerformLayout Method

정의

컨트롤이 자식 컨트롤에 레이아웃 논리를 강제로 적용하도록 합니다.Forces the control to apply layout logic to child controls.

오버로드

PerformLayout() PerformLayout() PerformLayout() PerformLayout()

컨트롤이 모든 자식 컨트롤에 레이아웃 논리를 강제로 적용하도록 합니다.Forces the control to apply layout logic to all its child controls.

PerformLayout(Control, String) PerformLayout(Control, String) PerformLayout(Control, String) PerformLayout(Control, String)

컨트롤이 모든 자식 컨트롤에 레이아웃 논리를 강제로 적용하도록 합니다.Forces the control to apply layout logic to all its child controls.

PerformLayout() PerformLayout() PerformLayout() PerformLayout()

컨트롤이 모든 자식 컨트롤에 레이아웃 논리를 강제로 적용하도록 합니다.Forces the control to apply layout logic to all its child controls.

public:
 void PerformLayout();
public void PerformLayout ();
member this.PerformLayout : unit -> unit
Public Sub PerformLayout ()

예제

다음 코드 예제에서는 PerformLayout 메서드를 사용하는 방법을 보여 줍니다.The following code example demonstrates how to use the PerformLayout method. 방법도 보여 줍니다는 Layout 이벤트가 발생 합니다.It also demonstrates ways in which the Layout event is raised. 이 예제는 Click 에 대 한 이벤트 처리기 Button1 명시적으로 호출 PerformLayout합니다.In this example, the Click event handler for Button1 explicitly calls PerformLayout. 합니다 Click 에 대 한 이벤트 처리기 Button2 암시적으로 호출 PerformLayout합니다.The Click event handler for Button2 implicitly calls PerformLayout. PerformLayout 폼이 로드 될 때 라고도 합니다.PerformLayout is also called when the form is loaded. Button3 컨트롤을 로드할 때의 상태로 돌아갑니다.Button3 returns the control to the state it was in when loaded. 각각의 경우에는 Layout 이벤트가 발생 합니다.In each case, the Layout event is raised.

전체 예제입니다.This is a complete example. 예제를 실행 하려면 빈 폼에 다음 코드를 붙여넣습니다.To run the example, paste the following code in a blank form.

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

// This custom control has the Layout event implented so that when 
// PerformLayout(AffectedControl, AffectedProperty) is called 
// on the control, where AffectedProperty equals "Bounds" the 
// textbox is centered on the control.
public ref class LayoutControl: public System::Windows::Forms::UserControl
{
public private:
   System::Windows::Forms::TextBox^ TextBox1;

public:
   LayoutControl()
      : UserControl()
   {
      InitializeComponent();
   }


private:
   void InitializeComponent()
   {
      this->TextBox1 = gcnew System::Windows::Forms::TextBox;
      this->SuspendLayout();
      this->TextBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->TextBox1->Name = "TextBox1";
      this->TextBox1->TabIndex = 0;
      this->BackColor = System::Drawing::SystemColors::ControlDark;
      this->Controls->Add( this->TextBox1 );
      this->Name = "LayoutControl";
      this->ResumeLayout( false );
      this->Layout += gcnew LayoutEventHandler( this, &LayoutControl::LayoutControl_Layout );
   }


   // This method is called when the Layout event is fired. 
   // This happens by during the initial load, by calling PerformLayout
   // or by resizing, adding or removing controls or other actions that 
   // affect how the control is laid out. This method checks the 
   // value of e.AffectedProperty and changes the look of the 
   // control accordingly. 
   void LayoutControl_Layout( Object^ /*sender*/, System::Windows::Forms::LayoutEventArgs^ e )
   {
      if ( e->AffectedProperty != nullptr )
      {
         if ( e->AffectedProperty->Equals( "Bounds" ) )
         {
            TextBox1->Left = (this->Width - TextBox1->Width) / 2;
            TextBox1->Top = (this->Height - TextBox1->Height) / 2;
         }
      }
      else
      {
         this->Size = System::Drawing::Size( 150, 160 );
         TextBox1->Location = System::Drawing::Point( 16, 24 );
      }

      TextBox1->Text = String::Format( "Left = {0} Top = {1}", TextBox1->Left, TextBox1->Top );
   }

};

public ref class LayoutForm: public System::Windows::Forms::Form
{
public:
   LayoutForm()
      : Form()
   {
      InitializeComponent();
   }


public private:
   System::Windows::Forms::Button^ Button1;
   System::Windows::Forms::Button^ Button2;
   LayoutControl^ LayoutControl1;
   System::Windows::Forms::Button^ Button3;

private:
   void InitializeComponent()
   {
      this->Button1 = gcnew System::Windows::Forms::Button;
      this->Button2 = gcnew System::Windows::Forms::Button;
      this->Button3 = gcnew System::Windows::Forms::Button;
      this->LayoutControl1 = gcnew LayoutControl;
      this->SuspendLayout();
      this->Button1->Location = System::Drawing::Point( 16, 16 );
      this->Button1->Name = "Button1";
      this->Button1->Size = System::Drawing::Size( 120, 32 );
      this->Button1->TabIndex = 0;
      this->Button1->Text = "Center textbox on control";
      this->Button2->Location = System::Drawing::Point( 152, 16 );
      this->Button2->Name = "Button2";
      this->Button2->Size = System::Drawing::Size( 104, 32 );
      this->Button2->TabIndex = 3;
      this->Button2->Text = "Shrink user control";
      this->Button3->Location = System::Drawing::Point( 96, 232 );
      this->Button3->Name = "Button3";
      this->Button3->TabIndex = 5;
      this->Button3->Text = "Reset";
      this->LayoutControl1->BackColor = System::Drawing::SystemColors::ControlDark;
      this->LayoutControl1->Location = System::Drawing::Point( 72, 64 );
      this->LayoutControl1->Name = "LayoutControl1";
      this->LayoutControl1->Size = System::Drawing::Size( 150, 160 );
      this->LayoutControl1->TabIndex = 6;
      this->ClientSize = System::Drawing::Size( 292, 266 );
      this->Controls->Add( this->Button3 );
      this->Controls->Add( this->Button2 );
      this->Controls->Add( this->Button1 );
      this->Controls->Add( this->LayoutControl1 );
      this->Name = "Form1";
      this->Text = "Form1";
      this->ResumeLayout( false );
      this->Button1->Click += gcnew System::EventHandler( this,&LayoutForm::Button1_Click );
      this->Button2->Click += gcnew System::EventHandler( this,&LayoutForm::Button2_Click );
      this->Button3->Click += gcnew System::EventHandler( this,&LayoutForm::Button3_Click );
   }


   // This method explicitly calls raises the layout event on 
   // LayoutControl1, changing the Bounds property.
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->PerformLayout( LayoutControl1, "Bounds" );
   }


   // This resize of LayoutControl1 implicitly triggers the layout event. 
   //  Changing the size of the control affects its Bounds property.
   void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->Size = System::Drawing::Size( 100, 100 );
   }


   // This method explicitly calls PerformLayout with no parameters, 
   // which raises the Layout event with the LayoutEventArgs properties
   // equal to Nothing.
   void Button3_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->PerformLayout();
   }

};


[System::STAThread]
int main()
{
   Application::Run( gcnew LayoutForm );
}


using System.Windows.Forms;
using System.Drawing;



public class LayoutForm:
	System.Windows.Forms.Form

{
	public LayoutForm() : base()
	{        
		InitializeComponent();
	}

	internal System.Windows.Forms.Button Button1;
	internal System.Windows.Forms.Button Button2;
	internal LayoutControl LayoutControl1;
	internal System.Windows.Forms.Button Button3;

	private void InitializeComponent()
	{
		this.Button1 = new System.Windows.Forms.Button();
		this.Button2 = new System.Windows.Forms.Button();
		this.Button3 = new System.Windows.Forms.Button();
		this.LayoutControl1 = new LayoutControl();
		this.SuspendLayout();
		this.Button1.Location = new System.Drawing.Point(16, 16);
		this.Button1.Name = "Button1";
		this.Button1.Size = new System.Drawing.Size(120, 32);
		this.Button1.TabIndex = 0;
		this.Button1.Text = "Center textbox on control";
		this.Button2.Location = new System.Drawing.Point(152, 16);
		this.Button2.Name = "Button2";
		this.Button2.Size = new System.Drawing.Size(104, 32);
		this.Button2.TabIndex = 3;
		this.Button2.Text = "Shrink user control";
		this.Button3.Location = new System.Drawing.Point(96, 232);
		this.Button3.Name = "Button3";
		this.Button3.TabIndex = 5;
		this.Button3.Text = "Reset";
		this.LayoutControl1.BackColor = System.Drawing.SystemColors.ControlDark;
		this.LayoutControl1.Location = new System.Drawing.Point(72, 64);
		this.LayoutControl1.Name = "LayoutControl1";
		this.LayoutControl1.Size = new System.Drawing.Size(150, 160);
		this.LayoutControl1.TabIndex = 6;
		this.ClientSize = new System.Drawing.Size(292, 266);
		this.Controls.Add(this.Button3);
		this.Controls.Add(this.Button2);
		this.Controls.Add(this.Button1);
		this.Controls.Add(this.LayoutControl1);
		this.Name = "Form1";
		this.Text = "Form1";
		this.ResumeLayout(false);
		this.Button1.Click += new System.EventHandler(Button1_Click);
		this.Button2.Click += new System.EventHandler(Button2_Click);
		this.Button3.Click += new System.EventHandler(Button3_Click);

	}

	[System.STAThread]
	public static void Main()
	{
		Application.Run(new LayoutForm());
	}


	// This method explicitly calls raises the layout event on 
	// LayoutControl1, changing the Bounds property.
	private void Button1_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.PerformLayout(LayoutControl1, "Bounds");
	}

	// This resize of LayoutControl1 implicitly triggers the layout event. 
	//  Changing the size of the control affects its Bounds property.
	private void Button2_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.Size = new System.Drawing.Size(100, 100);
	}

	// This method explicitly calls PerformLayout with no parameters, 
	// which raises the Layout event with the LayoutEventArgs properties
	// equal to Nothing.
	private void Button3_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.PerformLayout();
	}

}


// This custom control has the Layout event implented so that when 
// PerformLayout(AffectedControl, AffectedProperty) is called 
// on the control, where AffectedProperty equals "Bounds" the 
// textbox is centered on the control.
public class LayoutControl:
	System.Windows.Forms.UserControl
{
	internal System.Windows.Forms.TextBox TextBox1;

	public LayoutControl() : base()
	{        
		InitializeComponent();
	}

	private void InitializeComponent()
	{
		this.TextBox1 = new System.Windows.Forms.TextBox();
		this.SuspendLayout();
		this.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.TextBox1.Name = "TextBox1";
		this.TextBox1.TabIndex = 0;
		this.BackColor = System.Drawing.SystemColors.ControlDark;
		this.Controls.Add(this.TextBox1);
		this.Name = "LayoutControl";
		this.ResumeLayout(false);
		this.Layout += new LayoutEventHandler(LayoutControl_Layout);

	}

	// This method is called when the Layout event is fired. 
	// This happens by during the initial load, by calling PerformLayout
	// or by resizing, adding or removing controls or other actions that 
	// affect how the control is laid out. This method checks the 
	// value of e.AffectedProperty and changes the look of the 
	// control accordingly. 
	private void LayoutControl_Layout(object sender, 
		System.Windows.Forms.LayoutEventArgs e)
	{
		if (e.AffectedProperty != null)
		{
			if (e.AffectedProperty.Equals("Bounds"))
			{
				TextBox1.Left = (this.Width-TextBox1.Width)/2;
				TextBox1.Top = (this.Height-TextBox1.Height)/2;
			}
		}
		else
		{
			this.Size = new System.Drawing.Size(150, 160);
			TextBox1.Location = new System.Drawing.Point(16, 24);
		}
		TextBox1.Text = "Left = "+TextBox1.Left+" Top = "+TextBox1.Top;
	}

}


Imports System.Windows.Forms
Imports System.Drawing



Public Class LayoutForm
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents LayoutControl1 As LayoutControl
    Friend WithEvents Button3 As System.Windows.Forms.Button

    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.LayoutControl1 = New LayoutControl
        Me.SuspendLayout()
        Me.Button1.Location = New System.Drawing.Point(16, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(120, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Center textbox on control"
        Me.Button2.Location = New System.Drawing.Point(152, 16)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(104, 32)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Shrink user control"
        Me.Button3.Location = New System.Drawing.Point(96, 232)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 5
        Me.Button3.Text = "Reset"
        Me.LayoutControl1.BackColor = System.Drawing.SystemColors.ControlDark
        Me.LayoutControl1.Location = New System.Drawing.Point(72, 64)
        Me.LayoutControl1.Name = "LayoutControl1"
        Me.LayoutControl1.Size = New System.Drawing.Size(150, 160)
        Me.LayoutControl1.TabIndex = 6
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.LayoutControl1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

    <System.STAThread()> Shared Sub Main()
        Application.Run(New LayoutForm)
    End Sub


   
    ' This method explicitly calls raises the layout event on 
    ' LayoutControl1, changing the Bounds property.
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        LayoutControl1.PerformLayout(LayoutControl1, "Bounds")
    End Sub

    ' This resize of LayoutControl1 implicitly triggers the layout event. 
    '   Changing the size of the control affects its Bounds property.
    Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
        LayoutControl1.Size = New System.Drawing.Size(100, 100)
    End Sub

    ' This method explicitly calls PerformLayout with no parameters, 
    ' which raises the Layout event with the LayoutEventArgs properties
    ' equal to Nothing.
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        LayoutControl1.PerformLayout()
    End Sub

End Class


'This custom control has the Layout event implented so that when 
'PerformLayout(AffectedControl, AffectedProperty) is called on the control, 
'where AffectedProperty equals "Bounds" the textbox is centered on the control.
Public Class LayoutControl
    Inherits System.Windows.Forms.UserControl
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.TabIndex = 0
        Me.BackColor = System.Drawing.SystemColors.ControlDark
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "LayoutControl"
        Me.ResumeLayout(False)

    End Sub

    'This method is called when the Layout event is fired. This happens by during the initial load,
    'by calling PerformLayout or by resizing, adding or removing controls or other actions that 
    'affect how the control is laid out. This method checks the value of e.AffectedProperty
    'and changes the look of the control accordingly. 
    Private Sub LayoutControl_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
        If e.AffectedProperty IsNot Nothing Then
            If e.AffectedProperty.Equals("Bounds") Then
                TextBox1.Left = (Me.Width - TextBox1.Width) / 2
                TextBox1.Top = (Me.Height - TextBox1.Height) / 2
            End If
        Else
            Me.Size = New System.Drawing.Size(150, 160)
            TextBox1.Location = New System.Drawing.Point(16, 24)
        End If
        TextBox1.Text = "Left = " & TextBox1.Left & " Top = " & TextBox1.Top
    End Sub

End Class

설명

경우는 SuspendLayout 메서드를 호출한 호출 하기 전에 PerformLayout 메서드를 Layout 이벤트가 발생 하지 않습니다.If the SuspendLayout method was called before calling the PerformLayout method, the Layout event is suppressed.

AffectedControlAffectedProperty 의 속성을 LayoutEventArgs 로 생성 된 null 때 지정 된 값이 없으면는 PerformLayout 메서드를 호출한 합니다.The AffectedControl and AffectedProperty properties of the LayoutEventArgs created are set to null if no values were provided when the PerformLayout method was called.

추가 정보

PerformLayout(Control, String) PerformLayout(Control, String) PerformLayout(Control, String) PerformLayout(Control, String)

컨트롤이 모든 자식 컨트롤에 레이아웃 논리를 강제로 적용하도록 합니다.Forces the control to apply layout logic to all its child controls.

public:
 void PerformLayout(System::Windows::Forms::Control ^ affectedControl, System::String ^ affectedProperty);
public void PerformLayout (System.Windows.Forms.Control affectedControl, string affectedProperty);
member this.PerformLayout : System.Windows.Forms.Control * string -> unit
Public Sub PerformLayout (affectedControl As Control, affectedProperty As String)

매개 변수

affectedControl
Control Control Control Control

가장 최근에 변경된 컨트롤을 나타내는 Control입니다.A Control that represents the most recently changed control.

affectedProperty
String String String String

컨트롤에서 가장 최근에 변경된 속성의 이름입니다.The name of the most recently changed property on the control.

예제

다음 코드 예제에서는 PerformLayout 메서드를 사용하는 방법을 보여 줍니다.The following code example demonstrates how to use the PerformLayout method. 방법도 보여 줍니다는 Layout 이벤트가 발생 합니다.It also demonstrates ways in which the Layout event is raised. 이 예제는 Click 에 대 한 이벤트 처리기 Button1 명시적으로 호출 PerformLayout합니다.In this example, the Click event handler for Button1 explicitly calls PerformLayout. 합니다 Click 에 대 한 이벤트 처리기 Button2 암시적으로 호출 PerformLayout합니다.The Click event handler for Button2 implicitly calls PerformLayout. PerformLayout 폼이 로드 될 때 라고도 합니다.PerformLayout is also called when the form is loaded. Button3 컨트롤을 로드할 때의 상태로 돌아갑니다.Button3 returns the control to the state it was in when loaded. 각각의 경우에는 Layout 이벤트가 발생 합니다.In each case, the Layout event is raised.

전체 예제입니다.This is a complete example. 예제를 실행 하려면 빈 폼에 다음 코드를 붙여넣습니다.To run the example, paste the following code in a blank form.

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

// This custom control has the Layout event implented so that when 
// PerformLayout(AffectedControl, AffectedProperty) is called 
// on the control, where AffectedProperty equals "Bounds" the 
// textbox is centered on the control.
public ref class LayoutControl: public System::Windows::Forms::UserControl
{
public private:
   System::Windows::Forms::TextBox^ TextBox1;

public:
   LayoutControl()
      : UserControl()
   {
      InitializeComponent();
   }


private:
   void InitializeComponent()
   {
      this->TextBox1 = gcnew System::Windows::Forms::TextBox;
      this->SuspendLayout();
      this->TextBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
      this->TextBox1->Name = "TextBox1";
      this->TextBox1->TabIndex = 0;
      this->BackColor = System::Drawing::SystemColors::ControlDark;
      this->Controls->Add( this->TextBox1 );
      this->Name = "LayoutControl";
      this->ResumeLayout( false );
      this->Layout += gcnew LayoutEventHandler( this, &LayoutControl::LayoutControl_Layout );
   }


   // This method is called when the Layout event is fired. 
   // This happens by during the initial load, by calling PerformLayout
   // or by resizing, adding or removing controls or other actions that 
   // affect how the control is laid out. This method checks the 
   // value of e.AffectedProperty and changes the look of the 
   // control accordingly. 
   void LayoutControl_Layout( Object^ /*sender*/, System::Windows::Forms::LayoutEventArgs^ e )
   {
      if ( e->AffectedProperty != nullptr )
      {
         if ( e->AffectedProperty->Equals( "Bounds" ) )
         {
            TextBox1->Left = (this->Width - TextBox1->Width) / 2;
            TextBox1->Top = (this->Height - TextBox1->Height) / 2;
         }
      }
      else
      {
         this->Size = System::Drawing::Size( 150, 160 );
         TextBox1->Location = System::Drawing::Point( 16, 24 );
      }

      TextBox1->Text = String::Format( "Left = {0} Top = {1}", TextBox1->Left, TextBox1->Top );
   }

};

public ref class LayoutForm: public System::Windows::Forms::Form
{
public:
   LayoutForm()
      : Form()
   {
      InitializeComponent();
   }


public private:
   System::Windows::Forms::Button^ Button1;
   System::Windows::Forms::Button^ Button2;
   LayoutControl^ LayoutControl1;
   System::Windows::Forms::Button^ Button3;

private:
   void InitializeComponent()
   {
      this->Button1 = gcnew System::Windows::Forms::Button;
      this->Button2 = gcnew System::Windows::Forms::Button;
      this->Button3 = gcnew System::Windows::Forms::Button;
      this->LayoutControl1 = gcnew LayoutControl;
      this->SuspendLayout();
      this->Button1->Location = System::Drawing::Point( 16, 16 );
      this->Button1->Name = "Button1";
      this->Button1->Size = System::Drawing::Size( 120, 32 );
      this->Button1->TabIndex = 0;
      this->Button1->Text = "Center textbox on control";
      this->Button2->Location = System::Drawing::Point( 152, 16 );
      this->Button2->Name = "Button2";
      this->Button2->Size = System::Drawing::Size( 104, 32 );
      this->Button2->TabIndex = 3;
      this->Button2->Text = "Shrink user control";
      this->Button3->Location = System::Drawing::Point( 96, 232 );
      this->Button3->Name = "Button3";
      this->Button3->TabIndex = 5;
      this->Button3->Text = "Reset";
      this->LayoutControl1->BackColor = System::Drawing::SystemColors::ControlDark;
      this->LayoutControl1->Location = System::Drawing::Point( 72, 64 );
      this->LayoutControl1->Name = "LayoutControl1";
      this->LayoutControl1->Size = System::Drawing::Size( 150, 160 );
      this->LayoutControl1->TabIndex = 6;
      this->ClientSize = System::Drawing::Size( 292, 266 );
      this->Controls->Add( this->Button3 );
      this->Controls->Add( this->Button2 );
      this->Controls->Add( this->Button1 );
      this->Controls->Add( this->LayoutControl1 );
      this->Name = "Form1";
      this->Text = "Form1";
      this->ResumeLayout( false );
      this->Button1->Click += gcnew System::EventHandler( this,&LayoutForm::Button1_Click );
      this->Button2->Click += gcnew System::EventHandler( this,&LayoutForm::Button2_Click );
      this->Button3->Click += gcnew System::EventHandler( this,&LayoutForm::Button3_Click );
   }


   // This method explicitly calls raises the layout event on 
   // LayoutControl1, changing the Bounds property.
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->PerformLayout( LayoutControl1, "Bounds" );
   }


   // This resize of LayoutControl1 implicitly triggers the layout event. 
   //  Changing the size of the control affects its Bounds property.
   void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->Size = System::Drawing::Size( 100, 100 );
   }


   // This method explicitly calls PerformLayout with no parameters, 
   // which raises the Layout event with the LayoutEventArgs properties
   // equal to Nothing.
   void Button3_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      LayoutControl1->PerformLayout();
   }

};


[System::STAThread]
int main()
{
   Application::Run( gcnew LayoutForm );
}


using System.Windows.Forms;
using System.Drawing;



public class LayoutForm:
	System.Windows.Forms.Form

{
	public LayoutForm() : base()
	{        
		InitializeComponent();
	}

	internal System.Windows.Forms.Button Button1;
	internal System.Windows.Forms.Button Button2;
	internal LayoutControl LayoutControl1;
	internal System.Windows.Forms.Button Button3;

	private void InitializeComponent()
	{
		this.Button1 = new System.Windows.Forms.Button();
		this.Button2 = new System.Windows.Forms.Button();
		this.Button3 = new System.Windows.Forms.Button();
		this.LayoutControl1 = new LayoutControl();
		this.SuspendLayout();
		this.Button1.Location = new System.Drawing.Point(16, 16);
		this.Button1.Name = "Button1";
		this.Button1.Size = new System.Drawing.Size(120, 32);
		this.Button1.TabIndex = 0;
		this.Button1.Text = "Center textbox on control";
		this.Button2.Location = new System.Drawing.Point(152, 16);
		this.Button2.Name = "Button2";
		this.Button2.Size = new System.Drawing.Size(104, 32);
		this.Button2.TabIndex = 3;
		this.Button2.Text = "Shrink user control";
		this.Button3.Location = new System.Drawing.Point(96, 232);
		this.Button3.Name = "Button3";
		this.Button3.TabIndex = 5;
		this.Button3.Text = "Reset";
		this.LayoutControl1.BackColor = System.Drawing.SystemColors.ControlDark;
		this.LayoutControl1.Location = new System.Drawing.Point(72, 64);
		this.LayoutControl1.Name = "LayoutControl1";
		this.LayoutControl1.Size = new System.Drawing.Size(150, 160);
		this.LayoutControl1.TabIndex = 6;
		this.ClientSize = new System.Drawing.Size(292, 266);
		this.Controls.Add(this.Button3);
		this.Controls.Add(this.Button2);
		this.Controls.Add(this.Button1);
		this.Controls.Add(this.LayoutControl1);
		this.Name = "Form1";
		this.Text = "Form1";
		this.ResumeLayout(false);
		this.Button1.Click += new System.EventHandler(Button1_Click);
		this.Button2.Click += new System.EventHandler(Button2_Click);
		this.Button3.Click += new System.EventHandler(Button3_Click);

	}

	[System.STAThread]
	public static void Main()
	{
		Application.Run(new LayoutForm());
	}


	// This method explicitly calls raises the layout event on 
	// LayoutControl1, changing the Bounds property.
	private void Button1_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.PerformLayout(LayoutControl1, "Bounds");
	}

	// This resize of LayoutControl1 implicitly triggers the layout event. 
	//  Changing the size of the control affects its Bounds property.
	private void Button2_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.Size = new System.Drawing.Size(100, 100);
	}

	// This method explicitly calls PerformLayout with no parameters, 
	// which raises the Layout event with the LayoutEventArgs properties
	// equal to Nothing.
	private void Button3_Click(System.Object sender, System.EventArgs e)
	{
		LayoutControl1.PerformLayout();
	}

}


// This custom control has the Layout event implented so that when 
// PerformLayout(AffectedControl, AffectedProperty) is called 
// on the control, where AffectedProperty equals "Bounds" the 
// textbox is centered on the control.
public class LayoutControl:
	System.Windows.Forms.UserControl
{
	internal System.Windows.Forms.TextBox TextBox1;

	public LayoutControl() : base()
	{        
		InitializeComponent();
	}

	private void InitializeComponent()
	{
		this.TextBox1 = new System.Windows.Forms.TextBox();
		this.SuspendLayout();
		this.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.TextBox1.Name = "TextBox1";
		this.TextBox1.TabIndex = 0;
		this.BackColor = System.Drawing.SystemColors.ControlDark;
		this.Controls.Add(this.TextBox1);
		this.Name = "LayoutControl";
		this.ResumeLayout(false);
		this.Layout += new LayoutEventHandler(LayoutControl_Layout);

	}

	// This method is called when the Layout event is fired. 
	// This happens by during the initial load, by calling PerformLayout
	// or by resizing, adding or removing controls or other actions that 
	// affect how the control is laid out. This method checks the 
	// value of e.AffectedProperty and changes the look of the 
	// control accordingly. 
	private void LayoutControl_Layout(object sender, 
		System.Windows.Forms.LayoutEventArgs e)
	{
		if (e.AffectedProperty != null)
		{
			if (e.AffectedProperty.Equals("Bounds"))
			{
				TextBox1.Left = (this.Width-TextBox1.Width)/2;
				TextBox1.Top = (this.Height-TextBox1.Height)/2;
			}
		}
		else
		{
			this.Size = new System.Drawing.Size(150, 160);
			TextBox1.Location = new System.Drawing.Point(16, 24);
		}
		TextBox1.Text = "Left = "+TextBox1.Left+" Top = "+TextBox1.Top;
	}

}


Imports System.Windows.Forms
Imports System.Drawing



Public Class LayoutForm
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents LayoutControl1 As LayoutControl
    Friend WithEvents Button3 As System.Windows.Forms.Button

    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.LayoutControl1 = New LayoutControl
        Me.SuspendLayout()
        Me.Button1.Location = New System.Drawing.Point(16, 16)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(120, 32)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Center textbox on control"
        Me.Button2.Location = New System.Drawing.Point(152, 16)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(104, 32)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Shrink user control"
        Me.Button3.Location = New System.Drawing.Point(96, 232)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 5
        Me.Button3.Text = "Reset"
        Me.LayoutControl1.BackColor = System.Drawing.SystemColors.ControlDark
        Me.LayoutControl1.Location = New System.Drawing.Point(72, 64)
        Me.LayoutControl1.Name = "LayoutControl1"
        Me.LayoutControl1.Size = New System.Drawing.Size(150, 160)
        Me.LayoutControl1.TabIndex = 6
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.LayoutControl1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

    <System.STAThread()> Shared Sub Main()
        Application.Run(New LayoutForm)
    End Sub


   
    ' This method explicitly calls raises the layout event on 
    ' LayoutControl1, changing the Bounds property.
    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        LayoutControl1.PerformLayout(LayoutControl1, "Bounds")
    End Sub

    ' This resize of LayoutControl1 implicitly triggers the layout event. 
    '   Changing the size of the control affects its Bounds property.
    Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
        LayoutControl1.Size = New System.Drawing.Size(100, 100)
    End Sub

    ' This method explicitly calls PerformLayout with no parameters, 
    ' which raises the Layout event with the LayoutEventArgs properties
    ' equal to Nothing.
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        LayoutControl1.PerformLayout()
    End Sub

End Class


'This custom control has the Layout event implented so that when 
'PerformLayout(AffectedControl, AffectedProperty) is called on the control, 
'where AffectedProperty equals "Bounds" the textbox is centered on the control.
Public Class LayoutControl
    Inherits System.Windows.Forms.UserControl
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.TabIndex = 0
        Me.BackColor = System.Drawing.SystemColors.ControlDark
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "LayoutControl"
        Me.ResumeLayout(False)

    End Sub

    'This method is called when the Layout event is fired. This happens by during the initial load,
    'by calling PerformLayout or by resizing, adding or removing controls or other actions that 
    'affect how the control is laid out. This method checks the value of e.AffectedProperty
    'and changes the look of the control accordingly. 
    Private Sub LayoutControl_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
        If e.AffectedProperty IsNot Nothing Then
            If e.AffectedProperty.Equals("Bounds") Then
                TextBox1.Left = (Me.Width - TextBox1.Width) / 2
                TextBox1.Top = (Me.Height - TextBox1.Height) / 2
            End If
        Else
            Me.Size = New System.Drawing.Size(150, 160)
            TextBox1.Location = New System.Drawing.Point(16, 24)
        End If
        TextBox1.Text = "Left = " & TextBox1.Left & " Top = " & TextBox1.Top
    End Sub

End Class

설명

경우는 SuspendLayout 메서드를 호출한 호출 하기 전에 PerformLayout 메서드를 Layout 이벤트가 발생 하지 않습니다.If the SuspendLayout method was called before calling the PerformLayout method, the Layout event is suppressed.

합니다 affectedControl 하 고 affectedProperty 매개 변수 둘 다로 설정할 수 있습니다 null합니다.The affectedControl and affectedProperty parameters can both be set to null. 이렇게 하면 합니다 AffectedControlAffectedProperty 의 속성을 LayoutEventArgs 로 설정 하기 위해 만든 null합니다.Doing so causes the AffectedControl and AffectedProperty properties of the LayoutEventArgs created to be set to null.

추가 정보

적용 대상