-
Apr 27th, 2008, 06:25 AM
#1
Thread Starter
Hyperactive Member
keypress problems
I'm trying to build a calculator and im really struggling to get to grips on the vb.net 2008 keypress ... dunno why! anyway
Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Chr(Keys.NumPad0) Then
Button0.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad1) Then
Button1.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad2) Then
Button2.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad3) Then
Button3.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad4) Then
Button4.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad5) Then
Button5.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad6) Then
Button6.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad7) Then
Button7.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad8) Then
Button8.PerformClick()
ElseIf e.KeyChar = Chr(Keys.NumPad9) Then
Button9.PerformClick()
End If
End Sub
This doesn't seem to work, i will also need it to capture for the plus, minus, divide and subtract buttons along with the return and enter buttons (for equals)
Any help please?
-
Apr 27th, 2008, 07:34 AM
#2
Re: keypress problems
Well it's quite simple, controls (like the form) only recieve key presses when they have focus, when you have buttons or other input controls on your form, they take focus, any keypress event will goto them and not the form.
You will need keyboard hooks, or maybe a context menu or other control can do it.
-
Apr 27th, 2008, 11:05 AM
#3
New Member
Re: keypress problems
u Can write code in ProcessCmdKey function which is overidable
write ur all code there and u will get desire output which u want
-
Apr 27th, 2008, 11:14 AM
#4
Re: keypress problems
I don't have a processcmdkey event type (vb05) is this a new feature to .net 2008 ?
-
Apr 27th, 2008, 11:32 AM
#5
Thread Starter
Hyperactive Member
Re: keypress problems
for Phill64
Visual Basic (Declaration)
Code:
<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Protected Overridable Function ProcessCmdKey ( _
ByRef msg As Message, _
keyData As Keys _
) As Boolean
Visual Basic (Usage)
Code:
Dim msg As Message
Dim keyData As Keys
Dim returnValue As Boolean
returnValue = Me.ProcessCmdKey(msg, _
keyData)
-
Apr 27th, 2008, 11:37 AM
#6
Re: keypress problems
An australian should be in bed right now ;p (i'm one to talk HAHA) thanks for the post, i hadn't heard of that before ;p
I take it then, you have resolved the issue from ajays advice, perhaps marking this thread as resolved is in order then
-
Apr 27th, 2008, 12:10 PM
#7
Thread Starter
Hyperactive Member
Re: keypress problems
nope still working on it... :P
Gotta get up in 4 hours for work and i cba to stop working on a private project lol.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|