Control not releasing focus on SmartPhone

  • Thread starter Thread starter HolySamosa
  • Start date Start date
H

HolySamosa

I've written a custom control in C# for the SmartPhone. After the
control receives focus, it will not release focus when I press the UP
or DOWN arrows, thus focus is stuck on my control. This happens even
on the most basic control possible (a control that just draws a
rectangle when focused).

What must I do to fix this? It's driving me mad, as I can't find any
mention online of others having the same problem....

Thanks,
Jeremy
 
Try this code

protected override void OnKeyDown(KeyEventArgs e)
{
switch(e.KeyData)
{
case Keys.Up:
for(int i=0;i<this.Parent.Controls.Count;i++)
{
if (this==this.Parent.Controls)
{
this.Parent.Controls[(i-1)>=0?i-1:this.Parent.Controls.Count-1].Focus();
i=this.Parent.Controls.Count;
}
}
e.Handled=true;
break;
case Keys.Down:
for(int i=0;i<this.Parent.Controls.Count;i++)
{
if (this==this.Parent.Controls)
{
this.Parent.Controls[(i+1)<this.Parent.Controls.Count?i+1:0].Focus();
i=this.Parent.Controls.Count;
}
}
e.Handled=true;
break;
default:
base.OnKeyDown (e);
break;
}
}

P.S. Can be optimized
 
Wow. Thanks.

So am I correct in saying that the Smartphone (or .NET CF) doesn't
automatically handle the navigation between controls in a form, but
instead it is the responsibility of the control implementor to move the
input focus to the next / previous control when the down / up buttons
are pressed?
 
Back
Top