473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

KeyEventArgs


can somebody help me please with this simple problem?

I have combo box with numbers for months in it and want user to be
able to select a month Say 3 (for March) simply by clicking a number
either from the top row of keyboard or from numeric keypad.

So far I got this work for the top row (numbers) on the keyboard but I
can not get it to work for selected number from numeric keypad.

I do this:

for top row (numbers)
if e.KeyCode >= Keys.D1 And e.KeyCode <= Keys.D9 then
strKey as String = chrW(e.KeyData)
end if

for numeric keypad
if e.keyCode >= Keys.NumPad1 and e.KeyCode <= Keys.NumPad9 then
strkey as String = ?????

Thank you,
Dino
Nov 21 '05 #1
4 2809
Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps
Nov 21 '05 #2
On Wed, 2 Mar 2005 21:29:02 -0800, Crouchie1998
<Cr**********@discussions.microsoft.com> wrote:
Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps


Nov 21 '05 #3
Hi,

thank you for your help. However, I need to get the value, not just
to check for it. I know how to check for the keys, what I need is the
value (e.g if D2 or NumPad2 then 2) so I can then select the 2nd
month.

I have several combo boxes on the form, some of which are dealing with
Strings (e.g. names of countries) which I am processing just fine, and
the others dealing with numbers (e.g. months). I process these fine
as well but only for numbers above QUERTY. What I need is the way to
do it for numeric keypad, too.

Here is the code I am using so far:

Private Sub WcboMonth_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles WcboMonth.KeyUp
If ((e.KeyCode >= Keys.D1) And (e.KeyCode <= Keys.D9)) Then

// THIS WORKS FINE
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) =
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
If ((e.KeyCode >= Keys.NumPad1) And (e.KeyCode <=
Keys.NumPad9)) Then

// THIS DOES NOT WORK (e.g. returns 'e' instead of 5)
Dim strString As String = ChrW(e.KeyData)
Dim index As Integer = 0

Dim i As Integer = 0
For i = 0 To WcboMonth.Items.Count - 1
If (WcboMonth.Items(i).Text.Chars(0) =
strString) Then
index = i
Exit For
End If
Next

WcboMonth.SelectedIndex = index
End If
End Sub

Any suggestions?

thank you
_dino_

On Wed, 2 Mar 2005 21:29:02 -0800, Crouchie1998
<Cr**********@discussions.microsoft.com> wrote:
Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps


Nov 21 '05 #4

Thank you for your help.

I find the way how to do this. For those interested, I used wrong
event handler. I used KeyUp instead of using KeyPress (... I know,
one of these things ...)

Anyways, use KeyPress instead of KeyUp or so and then you have
e.KeyChar available which will return you the character pressed no
matter wehter you are using numeric pad, or numbers above QUERTY.

_dino_

On Wed, 2 Mar 2005 21:29:02 -0800, Crouchie1998
<Cr**********@discussions.microsoft.com> wrote:
Here's your solution:

Start a new Windows application & add a combobox (ComboBox1) to your form

Now, paste in the code below:

Const WM_KEYDOWN As Integer = &H100

Protected Overrides Function ProcessCmdKey _
(ByRef msg As System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean

If msg.Msg = WM_KEYDOWN Then
Return Not (keyData >= Keys.NumPad0 And keyData <= Keys.NumPad9) _
AndAlso Not (keyData >= Keys.D0 And keyData <= Keys.D9)
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

-----------------------

It only allows you to type in numbers abover the QWERTY... & from the
numeric pad.

I hope this helps


Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dave | last post by:
The execution control does not jump here if I have button, textbox, etc in the window form. Works OK with an empty form. Thanks
1
by: Chaoxiang | last post by:
the KeyEventArgs.KeyCode is readonly, so I want to override it. How to do it? I create a class, public class ExteKeyEventArgs : KeyEventArgs { ExteKeyEventArgs(Keys keys) } but it has a...
8
by: Edward Diener | last post by:
If I try to reference System::Windows::Forms::KeyEventArgs in a header file I get the error: MyHeader.h(236) : error C2039: 'Windows' : is not a member of 'System' Any ideas why this is...
5
by: **Developer** | last post by:
How do I know if the value in a KeyEventArgs is printable? Basicacally, in KeyUp I'd like to know if the character is printable, as opposed to say, a backspace. I suppose I could check...
2
by: Martijn Mulder | last post by:
How can I check the state of the modifier keys (Alt, Control, Shift) when there is no System.Windows.Forms.KeyEventArgs-object available (i.e. when not responding to a key-event)?
3
by: =?Utf-8?B?cGFucGF3ZWw=?= | last post by:
Is there a way to quickly determine if the key pressed was from 'A'-'Z' or '0'-'9' range? I really don't like to write switch with every Keys.A, Keys.B, etc key listed Paul
1
vinci
by: vinci | last post by:
Help Me!!!! T_T I want to create an instance of System.Windows.Forms.KeyEventArgs in vb.net for me to be able to use the .keyCode method of that class...is this possible??? basically, i want...
1
by: Claudia Fong | last post by:
I have the code below: private void OnKeyDownHandler(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { TextBox2.Text = "You Entered: " + textBox1.Text; } }
1
by: Eggbertx | last post by:
Ok I made a Windows Applications that makes the computer beep at a certain frequency when you press a letter key. Problem is, it doesn't do anything when it i out of focus. How do I make it continue...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.