vendredi 17 avril 2015

C# Winforms, assigning parent to new child object, other than instantiating form

I have an MDI container with two child forms. We've been taught (and the MSDN documentation only gives the example) to use the keyword 'this', which assumes that the child object in question is being created from the MDI container itself.


If I were creating the object in the MDI container, this would be correct:



Form_Child2 child = new Form_Child2(textBox1.Text);
child.MdiParent = this;
child.Show();


Instead, I'm trying to do something more like:



Form_Child2 child = new Form_Child2(textBox1.Text);
child.MdiParent = Form_Parent;
child.Show();


However, this throws an error saying that "Form_Parent" is a type and cannot be used as a variable. I think I vaguely understand what it's getting at, but it's not clear. I've tried studying up on keyword 'this' a bit as well, but still stuck.


Aucun commentaire:

Enregistrer un commentaire