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