Поделиться через


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)]
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 элемента управления контейнера. Это свойство возвращает значение NULL, если элемент управления размещен внутри Internet Explorer или в другом контексте размещения, где отсутствует родительская форма.

Атрибуты

Примеры

В следующем примере кода показано, как создать две формы: Form1 и Form2. IsMdiContainer Задайте для свойства trueForm1 и сделайте его MdiParentForm2. Затем создайте кнопку на 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

Применяется к

См. также раздел