Partager via


HardwareButton.HardwareKey, propriété

Mise à jour : novembre 2007

Obtient ou définit l'une des valeurs de HardwareKeys à associer à un HardwareButton sur un Pocket PC.

Espace de noms :  Microsoft.WindowsCE.Forms
Assembly :  Microsoft.WindowsCE.Forms (dans Microsoft.WindowsCE.Forms.dll)

Syntaxe

'Déclaration
Public Property HardwareKey As HardwareKeys
'Utilisation
Dim instance As HardwareButton
Dim value As HardwareKeys

value = instance.HardwareKey

instance.HardwareKey = value
public HardwareKeys HardwareKey { get; set; }
public:
property HardwareKeys HardwareKey {
    HardwareKeys get ();
    void set (HardwareKeys value);
}
public function get HardwareKey () : HardwareKeys
public function set HardwareKey (value : HardwareKeys)

Valeur de propriété

Type : Microsoft.WindowsCE.Forms.HardwareKeys

Valeur de HardwareKeys.

Notes

Vous devez également affecter le formulaire ou le contrôle que vous souhaitez activer avec le bouton matériel à la propriété AssociatedControl.

Exemples

L'exemple de code suivant montre comment associer deux boutons matériels pour activer le formulaire actuel. Cet exemple de code fait partie d'un exemple plus développé fourni pour la classe HardwareButton.

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()
      hwb4 = 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
      hwb4.AssociatedControl = Me
      hwb1.HardwareKey = HardwareKeys.ApplicationKey1
      hwb4.HardwareKey = HardwareKeys.ApplicationKey4
   Catch exc As Exception
      MessageBox.Show(exc.Message + " Check if the hardware button is physically available on this device.")
   End Try
 End Sub

Private Overloads Sub OnKeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
    ' When a hardware button is pressed and released,
    ' this form receives the KeyUp event. The OnKeyUp
    ' method is used to determine which hardware
    ' button was pressed, because the event data
    ' specifies a member of the HardwareKeys enumeration.
    Select Case CType(e.KeyCode, HardwareKeys)
      Case HardwareKeys.ApplicationKey1
         statusBar1.Text = "Button 1 pressed."

      Case HardwareKeys.ApplicationKey4
         statusBar1.Text = "Button 4 pressed."

      Case Else
   End Select
End Sub
// Configure hardware buttons
// 1 and 4 to activate the current form.
private void HBConfig()
    {
        try 
        {
            hwb1 = new HardwareButton();
            hwb4 = new HardwareButton();
            hwb1.AssociatedControl = this;
            hwb4.AssociatedControl = this;
            hwb1.HardwareKey = HardwareKeys.ApplicationKey1;
            hwb4.HardwareKey = HardwareKeys.ApplicationKey4;
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message + " Check if the hardware button is physically available on this device.");
        }
}

// When a hardware button is pressed and released,
// this form receives the KeyUp event. The OnKeyUp
// method is used to determine which hardware
// button was pressed, because the event data
// specifies a member of the HardwareKeys enumeration.
private void OnKeyUp(object sender, KeyEventArgs e)
{
    switch ((HardwareKeys)e.KeyCode)
    {
        case HardwareKeys.ApplicationKey1:
            statusBar1.Text = "Button 1 pressed.";
            break;

        case HardwareKeys.ApplicationKey4:
            statusBar1.Text = "Button 4 pressed.";
            break;

        default:
            break;
    }
}

Autorisations

Plateformes

Windows Mobile pour Pocket PC

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Informations de version

.NET Compact Framework

Pris en charge dans : 3.5, 2.0

Voir aussi

Référence

HardwareButton, classe

Membres HardwareButton

Microsoft.WindowsCE.Forms, espace de noms