MDI app and hosted controls
-
Hi Could anyone please explain to me why the following results in two mdi forms but the textbox only appearing on the second one? Clearly there is some sort of mechanism preventing me from hosting the same control on two different forms but I can't find any documentation regarding this.
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.IsMdiContainer = true; TextBox box = new TextBox(); Form frmchild=new Form(); frmchild.MdiParent=this; frmchild.Controls.Add(box); frmchild.Show(); Form frmchild2=new Form(); frmchild2.MdiParent=this; frmchild2.Controls.Add(box); frmchild2.Show(); }
Thanks in advance! Ewan. -
Hi Could anyone please explain to me why the following results in two mdi forms but the textbox only appearing on the second one? Clearly there is some sort of mechanism preventing me from hosting the same control on two different forms but I can't find any documentation regarding this.
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.IsMdiContainer = true; TextBox box = new TextBox(); Form frmchild=new Form(); frmchild.MdiParent=this; frmchild.Controls.Add(box); frmchild.Show(); Form frmchild2=new Form(); frmchild2.MdiParent=this; frmchild2.Controls.Add(box); frmchild2.Show(); }
Thanks in advance! Ewan.Try this: public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.IsMdiContainer = true;
TextBox boxA = new TextBox(); TextBox boxB = new TextBox();
Form frmchild=new Form(); frmchild.MdiParent=this; frmchild.Controls.Add(boxA); frmchild.Show(); Form frmchild2=new Form(); frmchild2.MdiParent=this; frmchild2.Controls.Add(boxB); frmchild2.Show(); } There are 10 kinds of people in the world.
Those that read binary...
...and those who don't. -
Try this: public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.IsMdiContainer = true;
TextBox boxA = new TextBox(); TextBox boxB = new TextBox();
Form frmchild=new Form(); frmchild.MdiParent=this; frmchild.Controls.Add(boxA); frmchild.Show(); Form frmchild2=new Form(); frmchild2.MdiParent=this; frmchild2.Controls.Add(boxB); frmchild2.Show(); } There are 10 kinds of people in the world.
Those that read binary...
...and those who don't. -
Hi Could anyone please explain to me why the following results in two mdi forms but the textbox only appearing on the second one? Clearly there is some sort of mechanism preventing me from hosting the same control on two different forms but I can't find any documentation regarding this.
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); this.IsMdiContainer = true; TextBox box = new TextBox(); Form frmchild=new Form(); frmchild.MdiParent=this; frmchild.Controls.Add(box); frmchild.Show(); Form frmchild2=new Form(); frmchild2.MdiParent=this; frmchild2.Controls.Add(box); frmchild2.Show(); }
Thanks in advance! Ewan.I think your trying to add the same instance of a TextBox control to two different forms at the same time? This will not work because of threading, concurrency, message pump, and window handle issues. You MUST use two different instances of the control. Think about it. How is a dual-hosted, single instance control going to fire events in one window and not the other? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
No - i think you've missed the point of my original post. I know perfectly well I could do ask you suggest but that wasn't my question.
I answered your question with code. You need separate instances of the textbox -- one for each form. So yes, I answered your question. There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.