Ignore checkbox click when spacebar pressed

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
 
B

Batvanio

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);
}
}
 
B

Batvanio

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top