ContainerControl.ParentForm プロパティ
コンテナ コントロールが割り当てられるフォームを取得します。
Public ReadOnly Property ParentForm As Form
[C#]
public Form ParentForm {get;}
[C++]
public: __property Form* get_ParentForm();
[JScript]
public function get ParentForm() : Form;
プロパティ値
コンテナ コントロールが割り当てられる Form 。
使用例
[Visual Basic, C#, C++] この例では、 Form1
と Form2
の 2 つのフォームを作成します。 Form1
の IsMdiContainer プロパティを true に設定し、このフォームを Form2
の MdiParent にします。次に、各フォーム上にボタン (button1
) を作成します。親フォーム上のボタンがクリックされると、イベント ハンドラは子フォームを表示します。子フォーム上のボタンがクリックされると、イベント ハンドラは、その親フォームの Name プロパティを表示します。両方のフォームの button1
イベント ハンドラを上書きするには、次の 2 つのコード セグメントを使用します。
' 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 Form1()
' Make this form the parent of f2.
f2.MdiParent = Me
' Display the form.
f2.Show()
End Sub 'button1_Click
[C#]
// The event handler on Form1.
private void button1_Click(object sender, System.EventArgs e)
{
// Create an instance of Form2.
Form1 f2 = new Form1();
// Make this form the parent of f2.
f2.MdiParent = this;
// Display the form.
f2.Show();
}
[C++]
private:
// The event handler on Form1.
void button1_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
// Create an instance of Form2.
Form1* f2 = new Form1();
// Make this form the parent of f2.
f2->MdiParent = this;
// Display the form.
f2->Show();
}
[Visual Basic]
' 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 'button1_Click
[C#]
// 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 + ".");
}
[C++]
private:
// The event handler on Form2.
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(S"My Parent is ", s, S"."));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- UIPermission (すべてのウィンドウでこのプロパティ値を取得するために必要なアクセス許可) UIPermissionWindow.AllWindows (関連する列挙体)
参照
ContainerControl クラス | ContainerControl メンバ | System.Windows.Forms 名前空間 | Form