Take a look at the design guidelines for Windows Mobile. Generally speaking
you shouldn't be implementing these controls - you should be following the
UI guidelines.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
What about radio buttons? Do I have to create a custom implementation
for these as well?- Hide quoted text -
- Show quoted text -
Unfortunately, having the radio buttons is a requirement of the
project. This is what I have so far:
1) A custom control that extends UserControl which will act as a
container to the individual radio buttons. It's called SelectOne
2) A custom control that extends UserControl which will represent the
individual radio buttons and the text label. It's called
SelectOneChoice
For each radio button, I am adding a new instance of SelectOneChoice
to SelectOne's Controls variable.
I am drawing the radio buttons by overriding SelectOneChoice's OnPaint
method. The drawing and layout are fine. The problem I am having is
navigating between radio buttons.
I have a variable in each SelectOneChoice which denotes whether the
user is "hovering" over the current radio button. If this is true,
then I change the font of the label from Black to Blue. I implement
this in SelectOneChoice's OnPaint by checking the value of the
hovering varible and writing the text in the appropriate color.
I register an event handler in SelectOne with each SelectOneChoice's
GotFocus and KeyPress events as follows:
foreach (ChoiceBean curRCTB in this.l_choices){
SelectOneChoice curKCISOC = new
SelectOneChoice(curRCTB.displayText, curRCTB.value);
this.Controls.Add(curKCISOC);
curKCISOC.TabIndex = curTabIndex++;
curKCISOC.Location = new Point(0, curY);
curKCISOC.KeyPress += new
KeyPressEventHandler(this.HandleRadioKeyPress);
curKCISOC.GotFocus += new
EventHandler(this.HandleRadioGotFocus);
curKCISOC.BringToFront();
curY += SelectOneChoice.CHOICE_RADIUS * 2
+SelectOneChoice.HEIGHT_PADDING + SelectOne.ROW_SPACING;
}
If I manually call the first SelectOneChoice's Focus() method, it
turns blue as expected. However, I can't navigate by pressing Up/Down
to the next radio button.
I've found a "hack" that overrides each SelectOneChoice's OnKeyPress
event handler which manually moves focus to the next radio button if
Keys.Up or Keys.Down is pressed.
Similary, if the user has hovered over the last radio button and
presses down, they must move to the next control on the base form,
which I have coded manually as well. The code is as follows:
protected override void OnKeyDown(KeyEventArgs e)
{
switch (e.KeyData)
{
case Keys.Down:
for (int i = 0; i < this.Parent.Controls.Count; i+
+)
{
if (this == this.Parent.Controls
)
{
if ((i - 1) >= 0)
{
this.Parent.Controls[(i - 1)].Focus();
}
else
{
Debug.WriteLine("Getting out of
control...");
((MainKioskClientForm)this.TopLevelControl).navigationLinksPanel.Controls[0]..Focus();
}
break;
}
}
e.Handled = true;
break;
case Keys.Up:
for (int i = 0; i < this.Parent.Controls.Count; i+
+)
{
if (this == this.Parent.Controls)
{
if ((i + 1) < this.Parent.Controls.Count)
{
this.Parent.Controls[(i + 1)].Focus();
}
break;
}
}
e.Handled = true;
break;
default:
base.OnKeyDown(e);
break;
}
}
Is this the proper way to do it? I'm surprised that I had to manually
assign focus when implementing the custom control.