HardwareButton クラスとは? わかりやすく解説

HardwareButton クラス

Pocket PCハードウェア ボタン機能オーバーライドできるようにします。

名前空間: Microsoft.WindowsCE.Forms
アセンブリ: Microsoft.WindowsCE.Forms (microsoft.windowsce.forms.dll 内)
構文構文

Public Class HardwareButton
    Inherits Component
Dim instance As HardwareButton
public class HardwareButton : Component
public ref class HardwareButton : public
 Component
public class HardwareButton extends Component
public class HardwareButton extends
 Component
解説解説

以下を実行することによって、アプリケーションFormPanel、またはカスタム コントロールアクティブにするように、Pocket PCボタン設定できます

ハードウェア ボタンコントロール関連付けると、そのコントロールは、ボタン押されときには KeyDown イベント受け取りボタン離されときには KeyUp イベント受け取ります

ハードウェア ボタンを元の状態に戻すには、AssociatedControl プロパティnull 参照 (Visual Basic では Nothing) に設定します

Pocket PC中にはハードウェア ボタンの数が 6 個ではないものもありますまた、オペレーティング システムによってすべてのボタンサポートされているわけではありません。Windows Mobile 2003 for Pocket PC では 4 個のボタンが、Windows Mobile Version 5.0 software for Pocket PC では 5 個のボタンサポートされています。

このクラスは、Smartphone および Pocket PC 以外の Windows CE デバイスではサポートされていません。

使用例使用例

Pocket PC1 つ目と 4 つ目のハードウェア ボタン使用してフォームアクティブにする方法次のコード例示します

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


Public Class Form1
   Inherits System.Windows.Forms.Form
   Private statusBar1 As StatusBar
   Private hwb1 As HardwareButton
   Private hwb4 As HardwareButton
   
   
   Public Sub New()
      
      InitializeComponent()
      
      ' Display OK button to close the application.
      Me.ControlBox = True
      Me.MinimizeBox = False
      
      ConfigHWButton()
      
      
   End Sub
   
   
   Protected Overrides Sub
 Dispose(disposing As Boolean)
      MyBase.Dispose(disposing)
   End Sub
   
   Private Sub 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."
   End Sub
    
   Shared Sub Main()
      Application.Run(New Form1())
   End Sub
   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
         MsgBox(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
End Class 
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace HardwareButtonTest
{
    public class 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();
        }

        protected override void Dispose(bool
 disposing)
        {
            base.Dispose(disposing);
        }
        private void 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.";

        }

        static void Main()
        {
            Application.Run(new Form1());
        }


        // 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;
            }
        }
    }
}
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
      Microsoft.WindowsCE.Forms.HardwareButton
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HardwareButton クラス」の関連用語

HardwareButton クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HardwareButton クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS