HardwareButton.AssociatedControl 屬性
取得或設定與 Pocket PC 上 HardwareButton 關聯的表單、面板或自訂控制項。
命名空間: Microsoft.WindowsCE.Forms
組件: Microsoft.WindowsCE.Forms (在 Microsoft.WindowsCE.Forms.dll 中)
語法
'宣告
Public Property AssociatedControl As Control
'用途
Dim instance As HardwareButton
Dim value As Control
value = instance.AssociatedControl
instance.AssociatedControl = value
public Control AssociatedControl { get; set; }
public:
property Control^ AssociatedControl {
Control^ get ();
void set (Control^ value);
}
public function get AssociatedControl () : Control
public function set AssociatedControl (value : Control)
屬性值
型別:System.Windows.Forms.Control
與 HardwareButton 關聯的控制項。
備註
您也必須將 HardwareKey 屬性設定為其中一個 HardwareKey 值。
範例
下列程式碼範例顯示如何產生兩個硬體按鈕的關聯,以啟動目前的表單。這個程式碼範例是 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 Mobile for Pocket PC
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Compact Framework
支援版本:3.5、2.0