473,490 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trap Return key

I have a problem trapping the return key. I thought if I added the
forms keydown event handler that this would do what I want. It did not
even go into the keydown event handler when I pressed return. I have a
form and three buttons. I assigned one button to the cancel button and
another to the accept button property. But the right button rarely gets
activated unless it just happens to have focus. So, I thought maybe I
need to trap the Return key with the keydown handler of the form, but
this did not do a thing. I even added keydown handlers for the buttons
themselves, but that did not do anything either. So, just how do I trap
the return key for when the return key is pressed no matter what control
might have focus?

Z.K.
Nov 11 '07 #1
3 2727
First set the keypreview property of the form to true ( standard = false )

Now you can trap all the keys pressed on form level on the event handlers
asociated to the keys

HTH

Michel

"Z.K." <no****@nospam.netschreef in bericht
news:eF**************@TK2MSFTNGP03.phx.gbl...
>I have a problem trapping the return key. I thought if I added the forms
keydown event handler that this would do what I want. It did not even go
into the keydown event handler when I pressed return. I have a form and
three buttons. I assigned one button to the cancel button and another to
the accept button property. But the right button rarely gets activated
unless it just happens to have focus. So, I thought maybe I need to trap
the Return key with the keydown handler of the form, but this did not do a
thing. I even added keydown handlers for the buttons themselves, but that
did not do anything either. So, just how do I trap the return key for when
the return key is pressed no matter what control might have focus?

Z.K.

Nov 11 '07 #2
ZK,

For the button there is only one event and that is the click.

On the other hand, why are you using the key down, the information comes as
the key is going up.

Cor

Nov 11 '07 #3


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

If e.KeyData = Keys.Enter Then

e.SuppressKeyPress = True

MsgBox("hi")

End If

End Sub

In this case the key up event isn`t even raised ( unless you hold the enter
key )



"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:45**********************************@microsof t.com...
ZK,

For the button there is only one event and that is the click.

On the other hand, why are you using the key down, the information comes
as the key is going up.

Cor

Nov 11 '07 #4

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

Similar topics

2
2144
by: GrelEns | last post by:
hello, i would like if this behaviour can be obtained from python : trap an attributeError from inside a subclassing dict class... (here is a silly examples to explain my question) class...
2
13394
by: Fred Sawtelle | last post by:
I'm trying to trap the Enter key in any of the key events (keypress, keydown, keyup) of the Windows .Net combobox control. Try as I might, I cannot get the event to respond to an Enter key press;...
10
2419
by: Mike D | last post by:
I have a table in SQL 2000 with a composite Primary Key on coulumns Instrument_ID (int) and WeekOf (smalldatetime.) I am running asp on win 2003. I insert values using a stored procedure from...
0
1570
by: OC | last post by:
Because of the requirements on a high-speed data entry form, I need to reliably trap certain keys (specifically the "/", "*", "-", and "+") keys on the 10-key pad and treat them as "Function keys"....
2
10079
by: David McDivitt | last post by:
Another fellow here must modify an application. On the web page, pressing the enter key causes the form to submit. What users want is to remove enter key functionality from within a textarea and...
6
2485
by: temper3243 | last post by:
Hi Can someone explain me what is happening below ? Why is it printing 401380 $ cat scanf.c #include<stdio.h> int main() { int i; scanf(" %d",&i);
17
1628
by: Army1987 | last post by:
If uMyInt_t is an unsigned integral type, is the following a necessary and sufficient condition that uMyInt_t has no trap representation? (uMyInt_t)(-1) >CHAR_BIT*sizeof(uMyInt_t)-1 That is,...
7
1445
by: thamizh.veriyan | last post by:
Hi, I am new to this community. I have a doubt regarding trap representations. I read in IBM's website that something like this is legal: int main(){ int x=3; {
8
13369
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
This is the 2nd time posting so sorry for duplications. I am using VB.NT 2005 & a standard Combobox. I've been wracking my brain over this problem for a over a month & cannot seem to find a way to...
0
7112
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
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
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
5448
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,...
1
4878
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...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.