ContainerControl.ParentForm 속성

정의

컨테이너 컨트롤이 할당된 폼을 가져옵니다.

public:
 property System::Windows::Forms::Form ^ ParentForm { System::Windows::Forms::Form ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form ParentForm { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ParentForm : System.Windows.Forms.Form
Public ReadOnly Property ParentForm As Form

속성 값

Form

컨테이너 컨트롤이 할당된 Form입니다. 컨트롤이 Internet Explorer 내부에 호스팅되어 있거나 부모 폼이 없는 다른 호스팅 컨텍스트에 호스팅되어 있는 경우 이 속성은 null을 반환합니다.

특성

예제

다음 코드 예제에서는 두 가지 폼 Form1 을 만드는 방법을 보여 있습니다 Form2. 의 IsMdiContainer 속성을 설정하고 해당 속성을 .의 Form2속성 Form1 true 으로 MdiParent 설정합니다. 다음으로 각 양식에 단추를 button1만듭니다. 부모 폼의 단추를 클릭하면 이벤트 처리기에 자식 폼이 표시됩니다. 자식 폼의 단추를 클릭하면 이벤트 처리기에 부모 폼의 속성이 Name 표시됩니다. 두 가지 형식의 이벤트 처리기를 덮어쓰 button1 려면 다음 두 코드 세그먼트를 사용합니다.

   // The event handler on Form1.
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Create an instance of Form2.
      Form1^ f2 = gcnew Form2;

      // Make this form the parent of f2.
      f2->MdiParent = this;

      // Display the form.
      f2->Show();
   }
// The event handler on Form1.
private void button1_Click(object sender, System.EventArgs e)
{
    // Create an instance of Form2.
    Form2 f2 = new Form2();
    // Make this form the parent of f2.
    f2.MdiParent = this;
    // Display the form.
    f2.Show();
}
' The event handler on Form1.
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Create an instance of Form2.
    Dim f2 As New Form2()
    ' Make this form the parent of f2.
    f2.MdiParent = Me
    ' Display the form.
    f2.Show()
End Sub
   // The event handler on Form2.
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Get the Name property of the Parent.
      String^ s = ParentForm->Name;

      // Display the name in a message box.
      MessageBox::Show( String::Concat( "My Parent is ", s, "." ) );
   }
// The event handler on Form2.
private void button1_Click(object sender, System.EventArgs e)
{
    // Get the Name property of the Parent.
    string s = ParentForm.Name;
    // Display the name in a message box.
    MessageBox.Show("My Parent is " + s + ".");
}
' The event handler on Form2.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Get the Name property of the parent.
    Dim s As String = ParentForm.Name
    ' Display the name in a message box.
    MessageBox.Show("My parent is " + s + ".")
End Sub

적용 대상

추가 정보