473,407 Members | 2,306 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.

KeyPress not fired in some cases when Form.KeyPreview is on

Hi,

I am running is some problems with the KeyPreview and KeyPress events.

The KeyPress event is only triggered when there this an focusable control on
the form. When all controls are disabled the Form.KeyPress event does not
trigger anymore.

A way to 'solve' this is to set the focus to the form, but during testing it
happens ofter the keypress event is not getting triggered on keys like
ENTER. Clicking a few times on the main form will get the even triggered
again.

Is there a good solution to solve this, or is there a way to convert the
keys in ProcessCmdKey() to keydata?

TIA,

Rene
Nov 17 '05 #1
1 6131
Hi Rene,

It seems like the keyPress event doesn't trigger sometimes for the Enter key
because KeyDown doesn't. I don't know why or where the event goes. Have you
considered using only the KeyUp event?

Christiaan.
....
this.KeyDown += new KeyEventHandler(MyKeyDownEventHandler);
this.KeyPress += new KeyPressEventHandler(MyKeyPressEventHandler);
this.KeyUp += new KeyEventHandler(MyKeyUpEventHandler);
this.Click+=new EventHandler(MyClickEventHandler);

}

public void MyKeyDownEventHandler(object sender,KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter) System.Console.Write("ENTER");
System.Console.WriteLine("down");
e.Handled=true;
}

public void MyKeyUpEventHandler(object sender,KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter) System.Console.Write("ENTER");
System.Console.WriteLine("up");
e.Handled=true;
}

public void MyKeyPressEventHandler(object sender,KeyPressEventArgs e)
{
if (e.KeyChar==13) System.Console.Write("ENTER");
System.Console.WriteLine("press");
e.Handled=true;
}

public void MyClickEventHandler(object sender,EventArgs e)
{
button1.Enabled=!button1.Enabled;
}

....
this.KeyPreview = true;

"Rene" <re**@nomail.inval> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...
Hi,

I am running is some problems with the KeyPreview and KeyPress events.

The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled the Form.KeyPress event does not
trigger anymore.

A way to 'solve' this is to set the focus to the form, but during testing it happens ofter the keypress event is not getting triggered on keys like
ENTER. Clicking a few times on the main form will get the even triggered
again.

Is there a good solution to solve this, or is there a way to convert the
keys in ProcessCmdKey() to keydata?

TIA,

Rene

Nov 17 '05 #2

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

Similar topics

2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
2
by: adawson | last post by:
Hi, I need to execute some code when form submission is stopped before the page is returned from the server. For example, a user clicks a button to submit the form, realizes they've made a...
1
by: Joost Kraaijeveld | last post by:
Hi all, In my application that is generated by Clarion an SQL0418N ("A statement contains a use of a parameter marker that is not valid.") occurs. In the explanation section it says "in some...
5
by: Ron Vecchi | last post by:
I know the math I need to perform on width and height to keep an aspect ratio but where and how would I implement keeping a set aspect ratio on a form when a user resizes it. Override OnResize?...
8
by: needin4mation | last post by:
Is this the correct way to resize the controls on a form when the form is resized? protected override void OnResize(EventArgs ea) { listViewFiles.Width= this.ClientSize.Width-5;...
3
by: sonic | last post by:
Hi, displaying information on a page as MS Word document seems to be as simple as: //OnLoad Response.ContentType = "application/msword"; Response.Write ( MyContentString ); (this assuming...
13
by: HABJAN ®iga | last post by:
I'am using form's keypreview property & keydown (on form) to look for hotkeys (alt+?) Everything works fine, except when i have focus on combobox. Then the event on form isn't raised. Can...
2
by: abid gee | last post by:
Please give a kind look on my question. and please comments. I am Using C# as development tool of Dot Net 2.0. I wrote a function read_data() that read data from Serial Port continuously.Till...
4
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
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
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
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
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
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,...
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.