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. Adding control at runtime

Adding control at runtime

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I have a usercontrol in form1 which has a button in it. When user press this button I create a FORM class and add my usercontrol to it with the code below:

    private void MaximizeButton_Click(object sender, EventArgs e) {
    Form form = new Form();
    Control c = this.Parent;
    form.Controls.Add(c);
    form.Controls[0].Dock = DockStyle.Fill;
    form.Controls[0].Location = new Point(0, 0);
    form.ShowDialog();
    }

    The second form shown correctly but the problem is the UserControl disappear from the main form. Any idea? Thanks

    Mazy
    "This chancy chancy chancy world."

    M 1 Reply Last reply
    0
    • M Mazdak

      I have a usercontrol in form1 which has a button in it. When user press this button I create a FORM class and add my usercontrol to it with the code below:

      private void MaximizeButton_Click(object sender, EventArgs e) {
      Form form = new Form();
      Control c = this.Parent;
      form.Controls.Add(c);
      form.Controls[0].Dock = DockStyle.Fill;
      form.Controls[0].Location = new Point(0, 0);
      form.ShowDialog();
      }

      The second form shown correctly but the problem is the UserControl disappear from the main form. Any idea? Thanks

      Mazy
      "This chancy chancy chancy world."

      M Offline
      M Offline
      mohammadSoft
      wrote on last edited by
      #2

      hi, you add contol to form,,you should add user control to form . private void MaximizeButton_Click(object sender, EventArgs e) { userControl1 c = new userControl1(); c.Dock = DockStyle.Fill; c.Location = new Point(0, 0); Form form = new Form(); form.Controls.Add(c); form.ShowDialog(); }

      M 1 Reply Last reply
      0
      • M mohammadSoft

        hi, you add contol to form,,you should add user control to form . private void MaximizeButton_Click(object sender, EventArgs e) { userControl1 c = new userControl1(); c.Dock = DockStyle.Fill; c.Location = new Point(0, 0); Form form = new Form(); form.Controls.Add(c); form.ShowDialog(); }

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thanks ,it works now but I have one more problem. This button will be placed inside different type of UserControls, so how can get which UserControl should be create other that using a factory for my constructors?

        Mazy
        "This chancy chancy chancy world."

        M 1 Reply Last reply
        0
        • M Mazdak

          Thanks ,it works now but I have one more problem. This button will be placed inside different type of UserControls, so how can get which UserControl should be create other that using a factory for my constructors?

          Mazy
          "This chancy chancy chancy world."

          M Offline
          M Offline
          mohammadSoft
          wrote on last edited by
          #4

          i don't understand exactly ,please explain more phone number : 09124603315 -- modified at 7:36 Monday 25th June, 2007

          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