Вопрос

I am working with c# windows application and i need to enter some record to database after inserting in to textbox. I have tried this code

private void textBoxItemCode_KeyDown(object sender, EventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
       MessageBox.Show("You have entered the correct key.");
    }

}

but i am getting an error near e.KeyCode so how to make it

Это было полезно?

Решение 2

It Should be like this :-

private void textBoxItemCode_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        MessageBox.Show("You have entered the correct key.");
    }

}

Другие советы

You need to use the following args

System.Windows.Forms.KeyEventArgs

Your handler should look like this

private void textBoxItemCode_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        MessageBox.Show("You have entered the correct key.");
    }

}

That way you have access to the KeyCode property which does not exist on the base EventArgs

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top