private void syntaxBox_KeyUp(object sender, KeyEventArgs e)
{
int index;
string actual;
string found;
// Do nothing for certain keys, such as navigation keys.
if ((e.KeyCode == Keys.Back) ||
(e.KeyCode == Keys.Left) ||
(e.KeyCode == Keys.Right) ||
(e.KeyCode == Keys.Up) ||
(e.KeyCode == Keys.Down) ||
(e.KeyCode == Keys.Delete) ||
(e.KeyCode == Keys.PageUp) ||
(e.KeyCode == Keys.PageDown) ||
(e.KeyCode == Keys.Home) ||
(e.KeyCode == Keys.End))
{
return;
}
// Store the actual text that has been typed.
actual = this.syntaxBox.Text;
// Find the first match for the typed value.
index = this.syntaxBox.FindString(actual);
// Get the text of the first match.
if (index > -1)
{
found = this.syntaxBox.Items[index].ToString();
// Select this item from the list.
this.syntaxBox.SelectedIndex = index;
// Select the portion of the text that was automatically
// added so that additional typing replaces it.
this.syntaxBox.SelectionStart = actual.Length;
this.syntaxBox.SelectionLength = found.Length;
}
}