Keypress event in main form

H

Himselff

Hi guys,

Sorry for the cross-post but the guys in simgle dot net seem a bit loose
when we talk of pocket pc,

Im trying to bin a key to a button whit the keypress event of the form, per
exemple i got a button called cmdProduction
i want when u strike the "P" or "p" key on the keyboard that the
button_click event fire,

so far i got this but it does not seem to work :

Private Sub FrmMain_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = "P" Or e.KeyChar = "p" Then

e.Handled = True

Call BtmProduit_Click(sender, e)

End If

end sub

This litle code dont even fire the keypress event of the form so im
wondering what im doiing wrong !

Thanks in advance !

Himselff
 
H

Himselff

Of course i did and all ive found is that one way would be the
registerHotkey api,

No way to do that the good old way ?

Thanks !
 
J

Jordan Irwin via DotNetMonster.com

Sorry to say that I don't have a solution for your problem, but I can maybe provide an explaination of why your technique is not working.

In C#,

The Form_Keypress event is not firing because the form is not the control with focus at the time of the keypress. In the full Framework, you can overcome this by setting the Forms KeyPreview property to true. This tells the Form to intercept all keypresses before sending them to the control that has focus. Unfortunatly, I don't see this property in the CF.

I have not used VB .NET any, so I can't be sure the same thing is happening for you.

Hope this maybe provides some insight, and possibly leads to a workaround.

*****************************************
* A copy of the whole thread can be found at:
* http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-compact-framework/9137
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abuse.aspx?aid=a0d53a6d9fc44258a46a2ba706836aa3
*****************************************
 
H

Himselff

Well im finding my way way trough the API, trying to find out how i could
get it to work as i need !

Thanks for trying =)

Him !
 
H

Himselff

Any of you guys have ever face this problem before ?
Ive tried trough the api and cannot figure out how to make ti work whit my
app,

It was so simple in VB and even embeded VB, im sure its still that easy,
just need to find out how !

Thanks in advance for futur help !

Him
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top