Hardware buttons

G

Guest

Is anyone else haveing problems with the hardware buttons in V2? I can't get
them to activate anything but what is set up in the OS.

Here's the code I'm testing.

------------------
Imports Microsoft.WindowsCE.Forms

Public Class Form1

Private Sub ConfigHWButton()
' Set KeyPreview to true so that the form
' will receive key events before they
' are passed to the control that has focus.

Me.KeyPreview = True

hwb1 = New HardwareButton()
hwb2 = New HardwareButton()

' Set the AssociatedControl property
' to the current form and configure the
' first and fourth buttons to activate the form.
Try
hwb1.AssociatedControl = Me
hwb2.AssociatedControl = Me
hwb1.HardwareKey = HardwareKeys.ApplicationKey1
hwb2.HardwareKey = HardwareKeys.ApplicationKey2
Catch exc As Exception
MsgBox(exc.Message & " Check if the hardware button is " & _
"physically available on this device.")
End Try
End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
ConfigHWButton()
End Sub


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case CType(e.KeyCode, HardwareKeys)
Case HardwareKeys.ApplicationKey1
MsgBox("1")
Case HardwareKeys.ApplicationKey2
MsgBox("2")
End Select
End Sub
End Class
 
G

Graf

Hi Robert,

I guess you made the same mistake, that I made when I first used the
code from the MSDN: You need to add ConfigHWButton() to the Form Load
event like:

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ConfigHWButton()
End Sub

Regards,
Andreas
 
G

Guest

Hi Andreas,

Well I did call the ConfigHWButton in the form activate event, so I thought
"well I've seen weirder things with the SDK than requiring you to do
something in Load and nowhere else" so I just tried it in load and it still
isn't working :(.

I've only been trying it on the TDS Recon so far (haven't even tried it in
the emulator since I've been having other issues with that). But if you've
gotten it to work I may try again. In the meantime the API code from V1.1
still works for what I want to do, I just thought this would be a lot cleaner
and easier to understand. Ah well. :)

Robert Brown
 
G

Graf

Hi Robert,

yes, it worked quite fine on my Axim x3i, so normally it should work
everywhere else in the same way according to the philosophie of the
..net framework ;-)

Good luck!

Regards,
Andreas
 

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