本文介绍了我想创建文本框的按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,我想创建textbox的按键事件实际上我已经使这个文本框进行了编程我想要按键事件,如果用户按任意键他们从数据库得到结果请帮助我。



提前致谢

Sajid。



我尝试过的方法:



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
                {

推荐答案

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.


这篇关于我想创建文本框的按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:51