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. Generating Buttons dynamically at runtime?

Generating Buttons dynamically at runtime?

Scheduled Pinned Locked Moved C#
questioncsharp
3 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.
  • E Offline
    E Offline
    E6AD
    wrote on last edited by
    #1

    Hi there, I am developing a C# application in which I would like to generate buttons/textboxes or whatever controls dynamically at runtime,The number of the controls to be generated will be determined in runtime..Do anyone have any idea can I do this..How can I generate them and then further access them to manipulate them??? Pleaaaaaaaaaaaaaaaaaaaaaaase HEEEEEEEEEEEEEEEEEEEEEEEEEEELP Best Regards, E.A.

    T 1 Reply Last reply
    0
    • E E6AD

      Hi there, I am developing a C# application in which I would like to generate buttons/textboxes or whatever controls dynamically at runtime,The number of the controls to be generated will be determined in runtime..Do anyone have any idea can I do this..How can I generate them and then further access them to manipulate them??? Pleaaaaaaaaaaaaaaaaaaaaaaase HEEEEEEEEEEEEEEEEEEEEEEEEEEELP Best Regards, E.A.

      T Offline
      T Offline
      therealmccoy
      wrote on last edited by
      #2

      I created the below code in VB.NET a while back. It will create as many textboxes as specified in 'mintLenCode' I used the "VB.Net to C# Converstion" program from www.vbconversions.com to do a quick port to C# (getting a lazy). Mind you I'm a newbie, so take it as it is. There might be a better way. private void CreateTextBoxes () { //Declare variables for textbox properties System.Drawing.Font Font = new System.Drawing.Font("Comic Sans MS", (float) (26.25), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); int counter = 0; int locationX = 16; //Size array based on length of mlng_CODE TxtBox = new TextBox[mintLenCode + 1]; //Create TextBoxes and set properties do { counter = counter + 1; TxtBox[counter] = new TextBox(); TxtBox[counter].Anchor = AnchorStyles.None; TxtBox[counter].Font = Font; TxtBox[counter].Location = new System.Drawing.Point(locationX, 152); TxtBox[counter].MaxLength = 1; TxtBox[counter].Size = new System.Drawing.Size(36, 56); TxtBox[counter].TabIndex = counter; TxtBox[counter].TextAlign = System.Windows.Forms.HorizontalAlignment.Center; TxtBox[counter].Name = System.Convert.ToString(counter); locationX = locationX + TxtBox[counter].Width; TxtBox[counter].KeyUp += new System.Windows.Forms.KeyEventHandler (txtbox_KeyUp); this.Controls.Add(TxtBox[counter]); } while (!(counter == mintLenCode)); } www.lovethosetrains.com

      E 1 Reply Last reply
      0
      • T therealmccoy

        I created the below code in VB.NET a while back. It will create as many textboxes as specified in 'mintLenCode' I used the "VB.Net to C# Converstion" program from www.vbconversions.com to do a quick port to C# (getting a lazy). Mind you I'm a newbie, so take it as it is. There might be a better way. private void CreateTextBoxes () { //Declare variables for textbox properties System.Drawing.Font Font = new System.Drawing.Font("Comic Sans MS", (float) (26.25), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); int counter = 0; int locationX = 16; //Size array based on length of mlng_CODE TxtBox = new TextBox[mintLenCode + 1]; //Create TextBoxes and set properties do { counter = counter + 1; TxtBox[counter] = new TextBox(); TxtBox[counter].Anchor = AnchorStyles.None; TxtBox[counter].Font = Font; TxtBox[counter].Location = new System.Drawing.Point(locationX, 152); TxtBox[counter].MaxLength = 1; TxtBox[counter].Size = new System.Drawing.Size(36, 56); TxtBox[counter].TabIndex = counter; TxtBox[counter].TextAlign = System.Windows.Forms.HorizontalAlignment.Center; TxtBox[counter].Name = System.Convert.ToString(counter); locationX = locationX + TxtBox[counter].Width; TxtBox[counter].KeyUp += new System.Windows.Forms.KeyEventHandler (txtbox_KeyUp); this.Controls.Add(TxtBox[counter]); } while (!(counter == mintLenCode)); } www.lovethosetrains.com

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

        Hi there, Thanks alot for your help..But the problem now is that ,when I create buttons whose location are outside the form size, I can see them..what would be the solution to that??? I don't want to resize the windows form as its size can exceed my monitor size,but I would rather prefer a scroll bar.. Any Idea how can I solve that?? Best Regards, E.A.

        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