Ignore checkbox click when spacebar pressed

  • Thread starter Thread starter joe.radjavitch
  • Start date Start date
J

joe.radjavitch

Hello,

I have a C# CF app that has a TabPage with a checkbox on it.

My app performs a particular function when the spacebar is pressed an
held.
If the checkbox has the focus before the spacebar is pressed, pressing
and holding the spacebar will cause the checkbox to toggle rapidly.

How do I add code to not toggle the checkbox when the spacebar is
pressed?

Thanks,
JR
 
Hello,

I have a C# CF app that has a TabPage with a checkbox on it.

My app performs a particular function when the spacebar is pressed an
held.
If the checkbox has the focus before the spacebar is pressed, pressing
and holding the spacebar will cause the checkbox to toggle rapidly.

How do I add code to not toggle the checkbox when the spacebar is
pressed?

Thanks,
JR

You might want to override the standard behavior and create your own
checkbox class derived from original, and then suppress the OnKeyUp/
Down handlers: Something like ths:

public class MyCheckBox : CheckBox
{
protected override void OnKeyUp(KeyEventArgs kevent)
{
if (kevent.KeyCode == Keys.Space)
return;

base.OnKeyUp(kevent);
}

protected override void OnKeyDown(KeyEventArgs kevent)
{
if (kevent.KeyCode == Keys.Space)
return;
base.OnKeyDown(kevent);
}
}
 
Hello,

I have a C# CF app that has a TabPage with a checkbox on it.

My app performs a particular function when the spacebar is pressed an
held.
If the checkbox has the focus before the spacebar is pressed, pressing
and holding the spacebar will cause the checkbox to toggle rapidly.

How do I add code to not toggle the checkbox when the spacebar is
pressed?

Thanks,
JR

You might want to override the standard behavior and create your own
checkbox class derived from original, and then suppress the OnKeyUp/
Down handlers: Something like ths:

public class MyCheckBox : CheckBox
{
protected override void OnKeyUp(KeyEventArgs kevent)
{
if (kevent.KeyCode == Keys.Space)
return;

base.OnKeyUp(kevent);
}

protected override void OnKeyDown(KeyEventArgs kevent)
{
if (kevent.KeyCode == Keys.Space)
return;
base.OnKeyDown(kevent);
}
}
 
Back
Top