Form.OwnedForms 属性
获取 Form 对象的数组,这些对象表示此窗体拥有的所有窗体。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public ReadOnly Property OwnedForms As Form()
用法
Dim instance As Form
Dim value As Form()
value = instance.OwnedForms
public Form[] OwnedForms { get; }
public:
property array<Form^>^ OwnedForms {
array<Form^>^ get ();
}
/** @property */
public Form[] get_OwnedForms ()
public function get OwnedForms () : Form[]
属性值
Form 数组,它表示此窗体的附属窗体。
备注
此属性返回包含此窗体拥有的所有窗体的数组。若要使某窗体归另一个窗体所有,请调用 AddOwnedForm 方法。分配给所有者窗体的窗体将保持被拥有状态,直到调用了 RemoveOwnedForm 方法。还可以让一个窗体归另一窗体所有,方法是设置带有对其所有者窗体的引用的 Owner 属性。
当一个窗体归另一窗体所有时,它便随着所有者窗体最小化和关闭。例如,如果 Form2
归窗体 Form1
所有,则关闭或最小化 Form1
时,Form2
也会关闭或最小化。并且附属窗体从不显示在其所有者窗体后面。可以将附属窗体用于查找和替换窗口之类的窗口;当所有者窗体被选定时,这些窗口不应显示在所有者窗体后。
提示
如果窗体是多文档界面 (MDI) 父窗体,则除了当前打开的所有 MDI 子窗体外,此属性将返回所有显示的窗体。若要获得 MDI 父窗体中打开的 MDI 子窗体,请使用 MdiChildren 属性。
示例
下面的代码示例演示如何使用 OwnedForms 属性修改所有者窗体所拥有的全部窗体。此示例中的第一个方法将窗体添加到与附属窗体关联的附属窗体数组中。第二个方法依次通过所有附属窗体,并更改标题。此示例要求两个方法均由事件调用或由窗体的其他方法调用。
Private Sub AddMyOwnedForm()
' Create form to be owned.
Dim ownedForm As New Form()
' Set the text of the owned form.
ownedForm.Text = "Owned Form " + Me.OwnedForms.Length.ToString()
' Add the form to the array of owned forms.
Me.AddOwnedForm(ownedForm)
' Show the owned form.
ownedForm.Show()
End Sub
Private Sub ChangeOwnedFormText()
Dim x As Integer
' Loop through all owned forms and change their text.
For x = 0 To (Me.OwnedForms.Length) - 1
Me.OwnedForms(x).Text = "My Owned Form " + x.ToString()
Next x
End Sub
private void AddMyOwnedForm()
{
// Create form to be owned.
Form ownedForm = new Form();
// Set the text of the owned form.
ownedForm.Text = "Owned Form " + this.OwnedForms.Length;
// Add the form to the array of owned forms.
this.AddOwnedForm(ownedForm);
// Show the owned form.
ownedForm.Show();
}
private void ChangeOwnedFormText()
{
// Loop through all owned forms and change their text.
for (int x = 0; x < this.OwnedForms.Length; x++)
{
this.OwnedForms[x].Text = "My Owned Form " + x.ToString();
}
}
private:
void AddMyOwnedForm()
{
// Create form to be owned.
Form^ ownedForm = gcnew Form;
// Set the text of the owned form.
ownedForm->Text = String::Format( "Owned Form {0}", this->OwnedForms->Length );
// Add the form to the array of owned forms.
this->AddOwnedForm( ownedForm );
// Show the owned form.
ownedForm->Show();
}
void ChangeOwnedFormText()
{
// Loop through all owned forms and change their text.
for ( int x = 0; x < this->OwnedForms->Length; x++ )
{
this->OwnedForms[ x ]->Text = String::Format( "My Owned Form {0}", x );
}
}
private void AddMyOwnedForm()
{
// Create form to be owned.
Form ownedForm = new Form();
// Set the text of the owned form.
ownedForm.set_Text("Owned Form " + this.get_OwnedForms().length);
// Add the form to the array of owned forms.
this.AddOwnedForm(ownedForm);
// Show the owned form.
ownedForm.Show();
} //AddMyOwnedForm
private void ChangeOwnedFormText()
{
// Loop through all owned forms and change their text.
for (int x = 0; x < this.get_OwnedForms().length; x++) {
this.get_OwnedForms()[x].set_Text("My Owned Form "
+ ((Int32)x).ToString());
}
} //ChangeOwnedFormText
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
Form 类
Form 成员
System.Windows.Forms 命名空间
AddOwnedForm
RemoveOwnedForm
Owner