SmartPhone CF: Making custom control for a form; How do I make it 'selectable' like other cont
Hi,
You how how SmartPhone forms, you can use up/down to select between standard controls?
This doesn't seem to work if you use a custom control. When I select a custom control (user written/third party written) that I've added to a form, the up/down arrow key gets stuck on it.
I have created a workaround, but it is somewhat arcane. I was wondering if there was a better method?
#if (__SMARTPHONE__)
protected override void OnKeyDown(KeyEventArgs e)
{
//-
// HACK: This is to allow selection of previous and next controls before and after this custom control.
// TBD: This needs to be replaced with a SmartPhone official method.
//-
Control prevCtl = null;
Control nextCtl = null;
bool found = false;
// Find the modifyable controls immediately prior and afterwards this control.
foreach (Control c in this.Parent.Controls)
{
if (!(c is Label))
{
if (c == this)
{
found = true;
}
else if (!found)
{
prevCtl = c;
}
else if (nextCtl == null)
{
nextCtl = c;
}
}
}
// Select the previous or next control, depending on whether up or down was pressed.
if (e.KeyCode == Keys.Up)
{
if (prevCtl != null) prevCtl.Focus();
}
else
{
if (nextCtl != null) nextCtl.Focus();
}
}
#endif

