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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Create and remove controls dynamically ??????

Create and remove controls dynamically ??????

Scheduled Pinned Locked Moved C#
question
4 Posts 4 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.
  • P Offline
    P Offline
    Pawan Kiran
    wrote on last edited by
    #1

    Hi I want to create controls dynamically in the form Initially i have textbox1 besides this button1 (text as Plus) when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) . e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls . thanks in advance...

    K P D 3 Replies Last reply
    0
    • P Pawan Kiran

      Hi I want to create controls dynamically in the form Initially i have textbox1 besides this button1 (text as Plus) when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) . e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls . thanks in advance...

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Sounds like homework. And it's not very difficult; look through the auto-generated code from another form for hints.

      1 Reply Last reply
      0
      • P Pawan Kiran

        Hi I want to create controls dynamically in the form Initially i have textbox1 besides this button1 (text as Plus) when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) . e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls . thanks in advance...

        K Offline
        K Offline
        kevinnicol
        wrote on last edited by
        #3

        You can move controls around on the form dynamically by setting their Control.Left and their Control.Top properties. As for creating new ones, it's also pretty simple, just create them in code, add them to the parent form then set their top and left Properties

        TextBox t = new TextBox();
        form1.Controls.Add(t);
        t.Top = 10;
        t.Left = 10;

        that should do it.

        1 Reply Last reply
        0
        • P Pawan Kiran

          Hi I want to create controls dynamically in the form Initially i have textbox1 besides this button1 (text as Plus) when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) . e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls . thanks in advance...

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          1. Create a user control that has Button and TextBox in it. 2. Add a FlowLayoutPanel to your form and set its FlowDirection as TopDown. 3. Handle the button click event of the button in the Form itself (through delegate). And then add and remove controls at your will. They will move up/down automatically.

          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