You can do this quite simply: just handle the TextBox.TextChanged event:
char[] illegalCharacters = "!$%@.,".ToCharArray();
private void myTextBox_TextChanged(object sender, EventArgs e)
{
TextBox t = sender as TextBox;
if (t != null)
{
string s = t.Text;
int index = s.IndexOfAny(illegalCharacters);
bool changed = false;
int cpos = t.SelectionStart;
while (index >= 0)
{
s = s.Remove(index, 1);
changed = true;
index = s.IndexOfAny(illegalCharacters);
}
if (changed)
{
t.Text = s;
t.SelectionStart = cpos < s.Length ? cpos : s.Length;
}
}
}