HardwareButton-Klasse

Dieser Dokumentation für die Vorschau nur ist und in späteren Versionen geändert. Leere Themen wurden als Platzhalter eingefügt.]

Ermöglicht das Überschreiben der Funktionen der Pocket PC-Tasten.

Namespace:  Microsoft.WindowsCE.Forms
Assembly:  Microsoft.WindowsCE.Forms (in Microsoft.WindowsCE.Forms.dll)

Syntax

'Declaration
Public Class HardwareButton _
    Inherits Component
'Usage
Dim instance As HardwareButton
public class HardwareButton : Component
public ref class HardwareButton : public Component
type HardwareButton =  
    class
        inherit Component
    end

Hinweise

Sie können eine Schaltfläche auf einem Pocket PC eine Form, Panel oder benutzerdefiniertes Steuerelement in Ihrer Anwendung aktivieren, indem wie folgt konfigurieren:

  • Erstellen Sie eine Instanz von HardwareButton.

  • Legen Sie die AssociatedControl-Eigenschaft auf das Formular oder Steuerelement aktiviert werden soll.

  • Legen Sie die HardwareKey -Eigenschaft auf eine HardwareKeys Enumerationswerte.Sie können bis zu sechs Tasten konfigurieren.

Wenn eine Taste mit einem Steuerelement verknüpft ist, erhält das Steuerelement ein Ereignis auf KeyDown , wenn die Schaltfläche gedrückt wird und ein KeyUp-Ereignis, wenn die Schaltfläche losgelassen wird.

Legen Sie die AssociatedControl -Eigenschaft auf nullNULL-Verweis (Nothing in Visual Basic), um eine Taste zu den ursprünglichen Zustand zurückzukehren.

Beachten Sie, dass einige Pocket PCs über eine unterschiedliche Anzahl von Tasten neben sechs verfügen.Nicht alle Schaltflächen werden auch vom Betriebssystem unterstützt.Windows Mobile 2003 für Pocket PC unterstützt vier Schaltflächen, und Windows Mobile 5.0 Software für Pocket PC unterstützt fünf Tasten.

Hinweis

Die Hardwaretasten entsprechen der Anwendungsschlüssel auf einem Pocket PC.Der Anwendungsschlüssel sind nicht in die Kerngruppe Schlüssel enthalten, so dass Ihre Hardware Tastenzuordnung aus ein Tastaturlayout zur nächsten variieren.Nur die Hardware Schlüssel Standardzuordnung auf dem Gerät wird unterstützt.

Diese Klasse wird nicht unterstützt, auf dem Smartphone und anderen Windows CE-Geräten, die keine Pocket PCs sind.

Beispiele

Im folgenden Codebeispiel wird das Aktivieren eines Formulars mithilfe der ersten und vierten Taste auf einem Pocket PC veranschaulicht.

Imports System
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms


PublicClass Form1
   Inherits System.Windows.Forms.Form
   Private statusBar1 As StatusBar
   Private hwb1 As HardwareButton
   Private hwb4 As HardwareButton


   PublicSubNew()

      InitializeComponent()

      ' Display OK button to close the application.Me.ControlBox = TrueMe.MinimizeBox = False

      ConfigHWButton()


   EndSubProtectedOverridesSub Dispose(disposing AsBoolean)
      MyBase.Dispose(disposing)
   EndSubPrivateSub InitializeComponent()
      Me.statusBar1 = New System.Windows.Forms.StatusBar()
      Me.hwb1 = New Microsoft.WindowsCE.Forms.HardwareButton
      Me.hwb4 = New Microsoft.WindowsCE.Forms.HardwareButton
      Me.SuspendLayout()
      '      ' statusBar1      'Me.statusBar1.Location = New System.Drawing.Point(0, 246)
      Me.statusBar1.Name = "statusBar1"Me.statusBar1.Size = New System.Drawing.Size(240, 22)
      '      ' Form1      'Me.ClientSize = New System.Drawing.Size(240, 268)
      Me.Controls.Add(statusBar1)
      Me.Name = "Form1"Me.Text = "HW Button Test"Me.ResumeLayout(False)
      statusBar1.Text = "From another app, press button 1 or 4."EndSubSharedSub Main()
      Application.Run(New Form1())
   EndSubPrivateSub 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.")
      EndTryEndSubPrivateOverloadsSub OnKeyUp(sender AsObject, e As KeyEventArgs) HandlesMyBase.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.SelectCaseCType(e.KeyCode, HardwareKeys)
         Case HardwareKeys.ApplicationKey1
            statusBar1.Text = "Button 1 pressed."Case HardwareKeys.ApplicationKey4
            statusBar1.Text = "Button 4 pressed."CaseElseEndSelectEndSubEndClass
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace HardwareButtonTest
{
    publicclass Form1 : System.Windows.Forms.Form
    {
        private StatusBar statusBar1;
        private HardwareButton hwb1, hwb4;

        public Form1()
        {

            InitializeComponent();

            // Display OK button to close the application.this.ControlBox = true;
            this.MinimizeBox = false;

            // Create event-handler delegate for the KeyUp// event for this form. This form is associated// with each of the hardware buttons, and the// event occurs when a hardware button is pressed.// Note that you could also use the KeyDown event// instead of the KeyUp event.this.KeyPreview = true;
            this.KeyUp += new KeyEventHandler(this.OnKeyUp);

            // Call the method to configure// the hardware button.
            HBConfig();
        }

        protectedoverridevoid Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
        privatevoid InitializeComponent()
        {
            this.statusBar1 = new System.Windows.Forms.StatusBar();
            this.SuspendLayout();
//// statusBar1//this.statusBar1.Location = new System.Drawing.Point(0, 246);
            this.statusBar1.Name = "statusBar1";
            this.statusBar1.Size = new System.Drawing.Size(240, 22);
//// Form1//this.ClientSize = new System.Drawing.Size(240, 268);
            this.Controls.Add(this.statusBar1);
            this.Name = "Form1";
            this.Text = "HW Button Test";
            this.ResumeLayout(false);
            statusBar1.Text = "Press hardware button 1 or 4.";

        }

        staticvoid Main()
        {
            Application.Run(new Form1());
        }


        // Configure hardware buttons// 1 and 4 to activate the current form.privatevoid 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.privatevoid 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;
            }
        }
    }
}

Vererbungshierarchie

System.Object
  System.MarshalByRefObject
    System.ComponentModel.Component
      Microsoft.WindowsCE.Forms.HardwareButton

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows Mobile für Pocket PC

Die .NET Framework und .NET Compact Framework unterstützen nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET framework.

Versionsinformationen

.NET Compact Framework

Unterstützt in: 3.5, 2.0

Siehe auch

Referenz

Member HardwareButton

Microsoft.WindowsCE.Forms-Namespace

Weitere Ressourcen

SO WIRD'S GEMACHT: Verwenden Sie die HardwareButton-Komponente