質問

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