473,407 Members | 2,320 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,407 software developers and data experts.

How to detect if "down" or "up" key is pressed?

7
I am having trouble detecting if "down" or "up" key is pressed within a textbox.

Evidently those keys do not fire the "KeyPressed" event.

Does anyone know how to detect when they are pressed?
Dec 18 '09 #1

✓ answered by tlhintoq

You should be able to intercept the message before it makes the move to begin with.

In your KeyDown handle method, it will have received a KeyPressArgs or something similar being assigned to variable e

You can then set e.Handled = true
So the OS doesn't pass the event any further, since you have handled it.

5 4563
GaryTexmo
1,501 Expert 1GB
Try the KeyDown event instead, it will get arrow key presses :)
Dec 18 '09 #2
tlhintoq
3,525 Expert 2GB
Check the args against the Keys.Down or Keys.Up
Dec 18 '09 #3
JamesX
7
Thanks, it worked great. But now I encountered another problem.

It seems that the Up and Down Key moves the selectIndex.

I adjusted it by simply adding or subtracting by 1. It doesn't work when the selection index is at the beginning and the end of the string since it seems to be increment/decrement after the event fired.

It won't let me increment pass the length of the string so if I press Up at the end of the string, it will always move the selectionIndex back 1.

Is there a way to disable moving the caret on up and down? or I have to use a round-bout method??
Dec 18 '09 #4
tlhintoq
3,525 Expert 2GB
You should be able to intercept the message before it makes the move to begin with.

In your KeyDown handle method, it will have received a KeyPressArgs or something similar being assigned to variable e

You can then set e.Handled = true
So the OS doesn't pass the event any further, since you have handled it.
Dec 18 '09 #5
JamesX
7
Thank you very much for the help :)
Sorry about being a total newbie at programming.
Much appreciated :)
Dec 18 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: djefanten | last post by:
Hi, I have a windows form with a combobox on it (it has the DropDown as DropDownStyle, which means you can type free text in it OR you can select from a list). At the moment that combobox...
17
by: in | last post by:
You know, why does Microsoft even bother to spend money to thwart Linux when it's top supporters act like such buffoons anyway...?! http://www.eweek.com/article2/0,1759,1772633,00.asp#talkback ...
18
by: Leslaw Bieniasz | last post by:
Cracow, 28.10.2004 Hello, I have a program that intensively allocates and deletes lots of relatively small objects, using "new" operator. The objects themselves are composed of smaller...
17
by: Will Hartung | last post by:
I have a table for a report. It can get wide, but that's no big deal. I don't mind that it can get wide. What I do mind, though, is the browser doing its damndest to smash the thing down to get...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
28
by: john_sips_tea | last post by:
Just tried Ruby over the past two days. I won't bore you with the reasons I didn't like it, however one thing really struck me about it that I think we (the Python community) can learn from. ...
0
by: U S Contractors Offering Service A Non-profit | last post by:
ALOT of them to pick from... Inbox Reply Craig Somerford to uscosoct24, Matthew, B-eing-I-nstru., Ed, me, New, mw, Natural, (bcc:USA), (bcc:Letters), (bcc:lvargas), (bcc:Le), (bcc:staff),...
10
by: JHNielson | last post by:
I am designing an interface, and I would like to customize the buttons instead of using the plain gray boxes that are standard in Access. Is there a way to set for the "On Mouse Up" and "On...
0
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.