Form.MdiChildren Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает массив форм, представляющих дочерние формы многодокументного интерфейса (MDI), родительские для этой формы.
public:
property cli::array <System::Windows::Forms::Form ^> ^ MdiChildren { cli::array <System::Windows::Forms::Form ^> ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form[] MdiChildren { get; }
[<System.ComponentModel.Browsable(false)>]
member this.MdiChildren : System.Windows.Forms.Form[]
Public ReadOnly Property MdiChildren As Form()
Значение свойства
Массив объектов, каждый из которых идентифицирует одну из дочерних Form форм этой формы MDI.
- Атрибуты
Примеры
В следующем примере показано, как использовать MdiChildren свойство для итерации списка дочерних форм MDI и добавления Button элемента управления в каждый элемент управления.
private:
void AddButtonsToMyChildren()
{
// If there are child forms in the parent form, add Button controls to them.
for ( int x = 0; x < this->MdiChildren->Length; x++ )
{
// Create a temporary Button control to add to the child form.
Button^ tempButton = gcnew Button;
// Set the location and text of the Button control.
tempButton->Location = Point(10,10);
tempButton->Text = "OK";
// Create a temporary instance of a child form (Form 2 in this case).
Form^ tempChild = dynamic_cast<Form^>(this->MdiChildren[ x ]);
// Add the Button control to the control collection of the form.
tempChild->Controls->Add( tempButton );
}
}
private void AddButtonsToMyChildren()
{
// If there are child forms in the parent form, add Button controls to them.
for (int x =0; x < this.MdiChildren.Length;x++)
{
// Create a temporary Button control to add to the child form.
Button tempButton = new Button();
// Set the location and text of the Button control.
tempButton.Location = new Point(10,10);
tempButton.Text = "OK";
// Create a temporary instance of a child form (Form 2 in this case).
Form tempChild = (Form)this.MdiChildren[x];
// Add the Button control to the control collection of the form.
tempChild.Controls.Add(tempButton);
}
}
Private Sub AddButtonsToMyChildren()
' If there are child forms in the parent form, add Button controls to them.
Dim x As Integer
For x = 0 To (Me.MdiChildren.Length) - 1
' Create a temporary Button control to add to the child form.
Dim tempButton As New Button()
' Set the location and text of the Button control.
tempButton.Location = New Point(10, 10)
tempButton.Text = "OK"
' Create a temporary instance of a child form (Form 2 in this case).
Dim tempChild As Form = CType(Me.MdiChildren(x), Form)
' Add the Button control to the control collection of the form.
tempChild.Controls.Add(tempButton)
Next x
End Sub
Комментарии
Это свойство позволяет получать ссылки на все дочерние формы MDI, открытые в родительской форме MDI. Чтобы создать дочернюю форму MDI, назначьте Form ее родительской форме MdiParent MDI свойству дочерней формы.
Это свойство можно использовать для цикла всех дочерних форм MDI для выполнения таких операций, как сохранение данных в базу данных при закрытии родительской формы MDI или обновлении полей дочерних форм на основе действий, выполняемых в приложении.