Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)

public Control AssociatedControl { get; set; }
/** @property */
public Control get_AssociatedControl ()

/** @property */
public void set_AssociatedControl (Control value)

public function get AssociatedControl () : Control

public function set AssociatedControl (value : Control)

Not applicable.

Property Value

The control associated with a HardwareButton.

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

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.

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Compact Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.