10 Replies - 4666 Views - Last Post: 23 July 2009 - 12:00 PM Rate Topic: -----

#1 Paat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-July 09

System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 07:36 AM

Hi, I'm trying to use the following code (found on this thread: http://www.dreaminco...topic112875.htm
Private Sub textbox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox2.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then

`//

End If
End Sub



I'm using Visual Studios and it gives me an error wehre textbox2.KeyPress (at KeyPress) because 'Event 'KeyPress'cannot be found'

I tried to add the System.Windows.Forms assembly but it didnt solve my problem. What do I do?

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: System.Windows.Forms Assembly for KeyPress Event

#2 PDUNZ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 375
  • Joined: 17-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 07:48 AM

Did you select "Keypress" from the text box's event properties and not just copy and paste? and you have a textbox name textbox2?

This post has been edited by PDUNZ: 21 July 2009 - 07:58 AM

Was This Post Helpful? 0
  • +
  • -

#3 Paat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 07:54 AM

View PostPDUNZ, on 21 Jul, 2009 - 06:48 AM, said:

Did you select "Keypress" from the text box's event properties? and not just copy and paste?


No there's no even property for the txtbox that is called KeyPress. Maybe its because I havent imported the assembly properly. I added System.Windows.Forms.dll into my bin with other dll's, and added Imports System.Windows.Forms to my code behind. Did i forget to do something?
Was This Post Helpful? 0
  • +
  • -

#4 PDUNZ  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 375
  • Joined: 17-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 08:05 AM

Visual Studio should already have those imported and set - check by going to the projects properties, and then selecting References.

The KeyPress even should look like this.
Attached Image


What version of Studio are you using?
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 09:59 AM

You've shown the KeyPress Event on TextBox1. The Code you show in the original post is for a Textbox named textbox2.
Was This Post Helpful? 0
  • +
  • -

#6 Paat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 21 July 2009 - 11:17 AM

i have visual stuoid 2008.

I checked again in the properties and i dont have a single of the event that are in your screenshot. These are the only ones i have:

DataBinding
Disposed
Init
Load
PreRender
TextChanged
Unload
Was This Post Helpful? 0
  • +
  • -

#7 Yaroslav94  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 294
  • Joined: 15-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 22 July 2009 - 01:12 PM

Hey... Why don't u try the keyup event..works better!

 Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
		If e.KeyCode = Keys.Enter Then
		  'What Ever You Want
End If 


Did I help??? If so thank me!
Was This Post Helpful? 0
  • +
  • -

#8 Paat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 22 July 2009 - 01:13 PM

Yaroslav94, the problem here is that i can't access the key events, so i can't access keydown, or keyup, or keypress. but thanks for trying!
Was This Post Helpful? 0
  • +
  • -

#9 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 22 July 2009 - 01:26 PM

Try doing this - select the name of the control (TextBox) in the class selection combo box (all this should be done in Code View). Then, in the method selection combo box select KeyPress. This will automatically generate the event handler.
Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 22 July 2009 - 01:31 PM

First off what are you trying to accomplish with this? I ask because there may be better options at your disposal.
Was This Post Helpful? 0
  • +
  • -

#11 Paat  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 21-July 09

Re: System.Windows.Forms Assembly for KeyPress Event

Posted 23 July 2009 - 12:00 PM

PsychoCode, i have a login page and i want the user to be able to login by pressing enter (as opposed to being force to click on the login button).

Core, i will try that when i get a chance. will give you the results.

PsychoCode, i have a login page and i want the user to be able to login by pressing enter (as opposed to being force to click on the login button).

Core, i will try that when i get a chance. will give you the results.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1