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. Creating Instance of button at run time.

Creating Instance of button at run time.

Scheduled Pinned Locked Moved C#
csharpgraphicsdata-structureshelp
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.
  • U Offline
    U Offline
    User 3950922
    wrote on last edited by
    #1

    Dear All Hi,I am new to csharp, I want to create a Bar Graph without using the graphics class, I want to use a button and adjust its size so that it looks like a bar.I will populate the properties of the buttons (size,color,position) at the run time. I need to create button instances at run time, I tried creating user objects of the button, but still I am unable to create many buttons at runtime. Any help or ideas will be appreciated . Thanks

    L 1 Reply Last reply
    0
    • U User 3950922

      Dear All Hi,I am new to csharp, I want to create a Bar Graph without using the graphics class, I want to use a button and adjust its size so that it looks like a bar.I will populate the properties of the buttons (size,color,position) at the run time. I need to create button instances at run time, I tried creating user objects of the button, but still I am unable to create many buttons at runtime. Any help or ideas will be appreciated . Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Button b = new Button()
      b.XXX = YYY; // set some properties here

      this.Controls.Add(b);

      regards

      U 1 Reply Last reply
      0
      • L Lost User

        Button b = new Button()
        b.XXX = YYY; // set some properties here

        this.Controls.Add(b);

        regards

        U Offline
        U Offline
        User 3950922
        wrote on last edited by
        #3

        Hi Greeg, If I had to create 100 buttons ,I do not want to write this code 100 times. I want something which is like cloning or creating Instances, for a user object button.Its not clear to me how we can do it in csharp.

        L 1 Reply Last reply
        0
        • U User 3950922

          Hi Greeg, If I had to create 100 buttons ,I do not want to write this code 100 times. I want something which is like cloning or creating Instances, for a user object button.Its not clear to me how we can do it in csharp.

          L Offline
          L Offline
          lisan_al_ghaib
          wrote on last edited by
          #4

          Buy a book int left = 0; int space = 1; //pix for ( int i = 0 ; i < nbButtons ; i++) { Button b = new Button(); b.name = i.ToString(); b.Text = i.ToString(); b.Left = left; c.Controls.Add (b); //C is a user control left += b.Left + b.Width + space; }

          U 1 Reply Last reply
          0
          • L lisan_al_ghaib

            Buy a book int left = 0; int space = 1; //pix for ( int i = 0 ; i < nbButtons ; i++) { Button b = new Button(); b.name = i.ToString(); b.Text = i.ToString(); b.Left = left; c.Controls.Add (b); //C is a user control left += b.Left + b.Width + space; }

            U Offline
            U Offline
            User 3950922
            wrote on last edited by
            #5

            Thanks Lisan I'll get some good books but until then this works. int left = 0; int space = 1; //pix int nbButtons = 5; for (int i = 0; i < nbButtons; i++) { GlassButton gb = new GlassButton(); gb.Name = i.ToString(); gb.Text = i.ToString(); gb.Left = left; gb.Location = new Point(20 + (i*5) , 10 + (i *5) ); this.Controls.Add(gb); //gb is a user control left += gb.Left + gb.Width + space; } Thanks again

            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