HardwareButton.AssociatedControl Property

Gets or sets a Form, Panel or custom control associated with a HardwareButton on a Pocket PC.

Namespace: Microsoft.WindowsCE.Forms
Assembly: Microsoft.WindowsCE.Forms (in microsoft.windowsce.forms.dll)

Syntax

'Declaration
Public Property AssociatedControl As Control
'Usage
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);
}
/** @property */
public Control get_AssociatedControl ()

/** @property */
public void set_AssociatedControl (Control value)
public function get AssociatedControl () : Control

public function set AssociatedControl (value : Control)

Property Value

The control associated with a HardwareButton.

Remarks

You must also set the HardwareKey property to one of HardwareKey values.

Example

The following code example shows how to associate two hardware buttons to activate the current form. This code example is part of a larger example provided for the HardwareButton class.

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
// 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;
    }
}

.NET Framework Security

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Platforms

Windows Mobile for Pocket PC

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Compact Framework

Supported in: 2.0

See Also

Reference

HardwareButton Class
HardwareButton Members
Microsoft.WindowsCE.Forms Namespace