Using Vs2003. cf1. c#. windows mobile 2003 (pocketpc)

Have added event hander in InitializeComponent()
this.KeyDown += new KeyEventHandler(this.MainForm_KeyDown);

Added method
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("Form Level KeyDown " + e.KeyCode);
}

The same form has 3 more buttons on the screen.

Now if launched and if user presses h/w enter key then get the o/p Form
Level KeyDown Return. Works as expected.

But after launching application if one would tap on any of the on-screen
buttons using the stylus and then hit the hardware ENTER key; now the event
does not fire at all.

Have confirmed this behavior using the Debug mode. How does one make sure
the Form Level KeyDown event always fires ? Basically need to force one of
the buttons to be the default buttons when h/w keyboard enter key is pressed.
Is their a better method to do this ?

TIA

Re: Form level KeyDown C#+ hardware keyboard enter key by ctacke/>

ctacke/>
Mon Apr 03 16:46:37 CDT 2006

Under CF 1.0 there is no key preview, and when something else gets focus, it
will get the key, not the Form. The workaround is an IMessageFilter
implementation.

-Chris


"handheldmaster" <handheldmaster@discussions.microsoft.com> wrote in message
news:AF44E996-70B4-4124-BEC8-C0CA240DC513@microsoft.com...
> Using Vs2003. cf1. c#. windows mobile 2003 (pocketpc)
>
> Have added event hander in InitializeComponent()
> this.KeyDown += new KeyEventHandler(this.MainForm_KeyDown);
>
> Added method
> private void MainForm_KeyDown(object sender, KeyEventArgs e)
> {
> MessageBox.Show("Form Level KeyDown " + e.KeyCode);
> }
>
> The same form has 3 more buttons on the screen.
>
> Now if launched and if user presses h/w enter key then get the o/p Form
> Level KeyDown Return. Works as expected.
>
> But after launching application if one would tap on any of the on-screen
> buttons using the stylus and then hit the hardware ENTER key; now the
> event
> does not fire at all.
>
> Have confirmed this behavior using the Debug mode. How does one make sure
> the Form Level KeyDown event always fires ? Basically need to force one of
> the buttons to be the default buttons when h/w keyboard enter key is
> pressed.
> Is their a better method to do this ?
>
> TIA



Re: Form level KeyDown C#+ hardware keyboard enter key by handheldmaster

handheldmaster
Tue Apr 04 08:51:04 CDT 2006


> Under CF 1.0 there is no key preview, and when something else gets focus, it
> will get the key, not the Form. The workaround is an IMessageFilter
> implementation.
>
Ok. Was able to use the OpenNetCF IMessageFilter and ApplicationEx.

What is the proper procedure to initialize the Message Filters ? If one does
an addMessageFilter do we need to do a removeMessageFilter as well ? Does it
have to be the same instance of the filter?

Is following the correct sequence ?
------------------------------------------------------
ApplicationEx.AddMessageFilter(new KeyFilter());
ApplicationEx.Run(new myForm());
------------------------------------------------------
Now in the Exit button code for myForm
ApplicationEx.removeMessageFilter(new KeyFilter());
ApplicationEx.Exit();
------------------------------------------------------

Basically have found that many a times even after the application is exited
it does unload completely from memory. If it is in this state and try to
redeploy get the sharing violation error. "Could not write to output file
myTestOCF.exe' - Sharing violation.

Only way to relaunch application is to soft-reset the device.