Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GUITestC {
public partial class Form1 : Form {
private TextBox[] txtBoxAr;
public Form1() {
InitializeComponent();
}
private void initTxtBox(ref TextBox[] txtBoxAr, int amount, int startx, int starty, int xspacing, int yspacing,int height,int width) {
txtBoxAr = new TextBox[amount];
int xoffset = width+xspacing;
int yoffset = height+yspacing;
for (int i = 0; i < amount; i++) {
txtBoxAr[i] = new TextBox();
txtBoxAr[i].Location = new System.Drawing.Point(startx+(i*xoffset), starty+ yoffset);
txtBoxAr[i].Name = "txtBoxAr"+i;
txtBoxAr[i].Size = new System.Drawing.Size(width, height);
this.Controls.Add(txtBoxAr);
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e) {
this.initTxtBox(ref this.txtBoxAr, 5, 10, 10, 10, 0, 20, 100);
}
}
}
Code:
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
note: this is the form ( got it from the form class )
=> Use eventHandlers, in this case an eventhandler for the form , that will fire up as soon as a key is pressed.
And please, if you have anymore questions not related to each other then post them in different threads. Else it will get too messy when someone is looking for something, or even trying to respond to your question.
:edit:
this.Form1_KeyDown instead of that garbage that shows up, also I dont have a clue why some of the code is in italics :s. ( probably because I use [ i ] somewhere and then had an initial .. )