共用方式為


HardwareKeys 列舉型別

設定 Pocket PC 上 HardwareButton 類別可以存取的硬體按鈕。

命名空間:  Microsoft.WindowsCE.Forms
組件:  Microsoft.WindowsCE.Forms (在 Microsoft.WindowsCE.Forms.dll 中)

語法

'宣告
Public Enumeration HardwareKeys
'用途
Dim instance As HardwareKeys
public enum HardwareKeys
public enum class HardwareKeys
public enum HardwareKeys

成員

成員名稱 說明
None 指定沒有實際的硬體按鈕與此 HardwareButton 執行個體關聯。
ApplicationKey1 指定與應用程式 1 相對應的硬體按鈕。
ApplicationKey2 指定與應用程式 2 相對應的硬體按鈕。
ApplicationKey3 指定與應用程式 3 相對應的硬體按鈕。
ApplicationKey4 指定與應用程式 4 相對應的硬體按鈕。
ApplicationKey5 指定與應用程式 5 相對應的硬體按鈕。
ApplicationKey6 指定與應用程式 6 相對應的硬體按鈕。

例外狀況

例外狀況 條件
NotSupportedException

備註

當使用者按下相對應的硬體按鈕時,此列舉中的某個成元的相關表單或控制項,就會收到相對應的 KeyDownKeyUp 事件。

Smartphone 以及其他不是 Pocket PC 的 Windows CE 裝置,均不支援此列舉型別,且列舉型別會擲回 NotSupportedException

範例

以下程式碼範例使用 AssociatedControlHardwareKey 屬性,每當 Pocket PC 上的第一個和第四個按鈕被按下時,都會顯示出一個表單。這個程式碼範例是 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;
    }
}

平台

Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Compact Framework

支援版本:3.5、2.0

請參閱

參考

Microsoft.WindowsCE.Forms 命名空間

其他資源

HOW TO:使用 HardwareButton 元件