Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i want to press the escape button so that the message box comes up, that doesn't work. When i fill in the number for escape and i press then on button 1 on the keyboard, it works perfect?

 

What has to be changed?

 

Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
       If e.KeyChar = "ESC" Then
           MsgBox("blabla", , "Product information")
       End If
   End Sub

Posted

It still doesn't work, now it gives an error on Handles button1, because that isn't in the System.Windows.Forms.Keys.

 

Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.Keys) Handles Button1.KeyPress ' <--------
       If e.KeyCode = Keys.Escape Then
           MsgBox("blabla", , "Product information")
       End If
   End Sub


  • Leaders
Posted

erm that form1_kepress looks a bit hey wire :-\ is it supposed to say handles button1.keypress when it's a form keypress event ?

Public Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.Keys) Handles Button1.KeyPress

the correct format for form keypress is this ...

   Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

   End Sub

Posted

ProcesCmdKey

 

try with this code ::

 

Protected Overrides Function ProcessCmdKey(ByRef msg As 
System.Windows.Forms.Message, ByVal keyData As 
System.Windows.Forms.Keys) As Boolean
       
If keyData = Keys.Escape Then
           MessageBox.Show("blah")
       End If

If keyData = Keys.A Then
           MessageBox.Show("A")
       End If

return true    

End Function

 

 

:D

Some people are wise and some are other-wise.
Posted

hmm look at the code u pasted above, it still says button1.keypress

 

if u have 'button1' on the form, then use Button1.keyup, but if u dont have a button on the form use form1.keyup, the reason is, when u have a button, the button has focus, so the Form1.keyup event wont work.. select Button1 and KeyUp and type

 

Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress

If e.keycode = keys.escape then
'blah
End If

 

End Sub

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

  • 2 weeks later...
Posted

KeyCode

 

Hi,

I'm using VB.Net

the vbKeyF5 code is &H74 and it givese me invalid synax error

 

If e.vbKeyF5 = Keys.F5 Then

blah

end if

 

 

Thanks for any help

  • *Experts*
Posted
You need to do it like this:
If e.KeyChar = Convert.ToChar(Keys.F5) Then

it's KeyChar not KeyCode, and you need to convert the Keys object to a char first.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...