Cannot find PreviewKeyDown Event??

tsdt

Active Member
Licensed User
Hi,

I found out that in .NET Framework 4, there is a PreviewKeyDownHandler Event in the Form Class which I noticed that Door.dll is not supporting.

In WinCE/WinMobile, there is no need to use this Event as everything will be trigger if KeyPreview = true. However, I noticed that for Window Embedded Standard, this is not true. Some of the keys like "Tab", "Enter", "Up", "Down", "Left", "Right" keys are not functioning as such under keyPress Event or Key Event.

We have tried to add in this Event into the dictionary of Door.dll, however, this keyevent is not even fired at all. If possible, can you please let know how whether the current B4PPC form does support this previewkeydown event?

If so, how can we trigger that event to fire?

Thanks heap.

Cheers,
Desmond:cool:
 

tsdt

Active Member
Licensed User
By default your program runs with .Net Framework 2.0. You will need to add a manifest file that makes it target .Net Framework 4.0.

Thank Erel for your reply.

We have .Net Framework 3.5 installed in our system. Any idea where is this manifest file is located in the system where we can change it to point to .Net Framework 4.0.

Cheers,
Desmond
 

tsdt

Active Member
Licensed User
Thank Erel for your reply.

We have .Net Framework 3.5 installed in our system. Any idea where is this manifest file is located in the system where we can change it to point to .Net Framework 4.0.

Cheers,
Desmond

I also noticed something.
A) Form control:
----------------
1) KeyDown for "Tab", "Enter", "Up", "Down", "Left", "Right" cannot work.
2) There is no PreviewKeyDownHandler Event.

B) Button control:
-----------------
1) KeyDown for "Tab", "Enter", "Up", "Down", "Left", "Right" cannot work.
2) There is no PreviewKeyDownHandler Event.

C) TextBox control:
-------------------
1) KeyDown for "Tab", "Enter", "Up", "Down", "Left", "Right" works.
2) There is no PreviewKeyDownHandler Event.

D) Num control:
---------------
1) KeyDown for "Tab", "Enter", "Up", "Down", "Left", "Right" cannot work.
 

tsdt

Active Member
Licensed User
Actually this event is not new in .Net 4.0. The problem is the the Door library doesn't support the PreviewKeyDownEventArgs object.

Erel, fully agreed. It is not new event in .Net 4.0.

I have tried to add in the PreviewKeyDownEvent in Door library. However, it is just not firing for the form control. Just wondering why it is not added for B4PPC Door library? Is there a problem after adding it?
 

agraham

Expert
Licensed User
Longtime User
To add a supported event to the Event object you should only need to add
B4X:
 d.Add(typeof(PreviewKeyDownEventHandler), new PreviewKeyDownEventHandler(eventHandler));
to the constructor of Event then it should just work.This event only exists on the desktop. However from MSDN
PreviewKeyDown ... occurs before the KeyDown event when a key is pressed while focus is on this control.
This event is not a general preview but is only for an individual control. If there are any focusable controls on the Form then the Form cannot get the focus and so you won't see this event.
 

tsdt

Active Member
Licensed User
To add a supported event to the Event object you should only need to add
B4X:
 d.Add(typeof(PreviewKeyDownEventHandler), new PreviewKeyDownEventHandler(eventHandler));
to the constructor of Event then it should just work.This event only exists on the desktop. However from MSDN
This event is not a general preview but is only for an individual control. If there are any focusable controls on the Form then the Form cannot get the focus and so you won't see this event.

Hi Agraham,

I did the d.Add in the Door.cs and compile for desktop. I am sure that the Form control is the focus when the Up Down key is pressed. For some reasons, we still could not get the PreviewKeyDownEventHandler to trigger. We were reading the MSDN and still could not figure out the reasons of it.

:BangHead:
 

tsdt

Active Member
Licensed User
Hi Agraham,

I did the d.Add in the Door.cs and compile for desktop. I am sure that the Form control is the focus when the Up Down key is pressed. For some reasons, we still could not get the PreviewKeyDownEventHandler to trigger. We were reading the MSDN and still could not figure out the reasons of it.

:BangHead:

We also noticed that for "Up", "Down", "Left", "Right", "Tab", and "Enter", for CE, the KeyDown event will fire when those keys are pressed. In Window Embedded Standard, it is not the case.

We had a work around for that problem, which is we have created a multi-line textbox, and focus on that textbox, those keys will fire the keydown event when pressed.

However, still cannot figure out why "PreviewKeyDownEventHandler" cant work when focus on the Form control, which is bothering me...
 
Top