Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MDI app and hosted controls

MDI app and hosted controls

Scheduled Pinned Locked Moved C#
hostingquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ewan
    wrote on last edited by
    #1

    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.

    L D 2 Replies Last reply
    0
    • E 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.

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      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.

      E 1 Reply Last reply
      0
      • L LongRange Shooter

        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.

        E Offline
        E Offline
        ewan
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • E 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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • E ewan

            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.

            L Offline
            L Offline
            LongRange Shooter
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups