views:

39

answers:

2

am using c# vs-2005

am on project to create textbox one by one on form1 and am success on button click event my code is below.

// declare location point of textbox on Global Area.
private point txtboxstartpoint=new point(10,10);

private void button_click (Object sender,EventArgs)
{
  Textbox tbx = new TextBox();
  tbx.Location= txtboxstartpoint;
  tbx.size=new size (200,20);
  this.panel1.control.add(tbx);
  txtboxstartpoint.y += 25;
}

this works fine on button click event but problem is on keypress event like on enter

i wants to create textbox on enter one by one. and for that i assume that any method have

to create and call enter keypress event on newly created control like textbox to create

another new textbox below the previous one.

Kindly help me. suggest proper code for the same.

+2  A: 

It's very hard to understand your question, but let's try some guessing:

You have a form, and if a user presses some specific key, you'd like to create a new TextBox and show it on your form regardless which control has currently the focus in your form.

If this statement is true, you can set Form.KeyPreview to true. And add an event handler to Form.KeyDown.

Due to the fact, that you set the preview to true you'll get every keyboard hit before it will be give further to the control that has currently the focus. So here you can check if the key that was pressed is the one you're listening for. And if yes, just call your TextBoxFactory and set the e.Handled to true to prevent that this key stroke will additionally reach the currently focused control.

Oliver
thx Oliver,yah! what i search is rare in googlesearch and that's why am here for help but finally i have worked hard on it and get success the same as i said above that very short code method is required i followed the same and got success and it's most demanded code what i generated. if u need than contact me at " [email protected]"
mahesh
@mahesh, please mark this as the answer.
Geoffrey Van Wyk
A: 

I use the KeyDown event, to intercept the 'F1' key to provide my small help in a very small programm. Here is the code:

private void MainForm_KeyDown(object sender, KeyEventArgs e)

    {
        if (e.KeyCode == Keys.F1)
        {
            //Your Code here
        }
    } 
ambassador86
thx ambassador86but what u suggest is time consume on data entry any way i worked hard on same and got success if u require the same then you may contact at "[email protected]" once again thank u very much.
mahesh