BlackStone
Regular
- Joined
- Jun 14, 2004
- Messages
- 75
I am writing a custom control, and I was wondering how I could capture the Tab key. I am sure it is a fairly common problem, but I could not seem to find it on google.
BlackStone said:I am using e.KeyData in OnKeyDown. It does not capture the tab key(it moves to the next tabstop instead).
BlackStone said:would I have to do something so dramatic?? There is no way I can just set an option somewhere?
_
public class Example : Control
{
public Example()
{
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyData == Keys.Tab)
{
// Won't ever reach this point.
// How can I fix that?
MessageBox.Show("Tab caught!");
}
else if (e.KeyData == Keys.A)
{
MessageBox.Show("The letter a is caught!");
}
}
}
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Tab Then
Return False
Else
Return MyBase.ProcessDialogKey(keyData)
End If
End Function