Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, i want to create keypress event of textbox actually i have made this textbox progrmatically i want keypress event for if user press any key they get result from database please help me.

Thanks in advance
Sajid.

What I have tried:

Form form = new Form();
            Label label = new Label();
            Label label90 = new Label();
            Label label91 = new Label();
            Label label92 = new Label();
            Label label93 = new Label();
            Label label94 = new Label();
            TextBox textBox = new TextBox();
            MaskedTextBox textBox00 = new MaskedTextBox();
            textBox00.Mask = "000000000000000";
            RichTextBox textBox000 = new RichTextBox();
            //TextBox dtp = new TextBox();
            //dtp.Enabled = false;
            //dtp.Format = DateTimePickerFormat.Custom;
            //dtp.CustomFormat = "hh:mm:ss:tt";
            TextBox name = new TextBox();
            TextBox location = new TextBox();
            MaskedTextBox CustomerCode = new MaskedTextBox();
            CustomerCode.Mask = "0000000";
            textBox00.MaxLength = 11;
            Button buttonOk = new Button();
            Button buttonCancel = new Button();
            form.Text = "Table1/Delivery";
            label.Text = "Name";
            label90.Text = "Phone No";
            label91.Text = "Address";
            label92.Text = "Location";
            label93.Text = "Rider Name";
            label94.Text = "Cstmr Code";
            textBox.Text = "";
            textBox00.Text = "";
            textBox000.Text = "";
            location.Text = "";
            name.Text = "";

            if (dialogResult == DialogResult.OK)
            {
                if (textBox00.Text == "" && CustomerCode.Text == "")
                {
                    MessageBox.Show("Please Enter Phone Number Or User Code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
Posted
Updated 11-Jan-17 1:12am

1 solution

Add the KeyPress event handler to your textbox:
myTextBox.KeyPress += myTextBox_KeyPress;

private void myTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    char pressed = e.KeyChar;
    ...
    }
You can then do what you like to access your DB and get results within the handler.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900