user1589801
user1589801

Reputation: 11

KeyPressEvent getting error

When i am using KeyPress(object sender,KeyPressEventArgs e) method it is displaying the following error:

The type or namespace name 'KeyPressEventArgs' could not be found (are you missing a using directive or an assembly reference?).

What is the name space for it

Upvotes: 1

Views: 2334

Answers (2)

h1ghfive
h1ghfive

Reputation: 206

Right click on your project -> Add reference and then select the dll which contain the keyPress class.

In the .cs file you are using the class, you need to import the referenced dll with using at the top of your file like this :

using System.Windows.Forms;

Additionnaly, if your application is web-based, you will not be able to do this. Better for you to check some Javascript for this, take a look at the jQuery lib.

Upvotes: 0

Dan Puzey
Dan Puzey

Reputation: 34198

KeyPressEventArgs is a Systems.Windows.Forms class. It's not intended for use in a web application - the web textbox control doesn't have this event (at least, on the server-side).

If you want to handle a keypress event in a webpage, you need to be doing this in Javascript (or equivalent) in the client's web browser.

Upvotes: 3

Related Questions