Is there an easy way for this?
About the set of characters allowed in a Windows file system (Char.IsLetterOrDigit is not enough)
How do I make the characters that are typed as uppercase?
Is there an easy way for this?
About the set of characters allowed in a Windows file system (Char.IsLetterOrDigit is not enough)
How do I make the characters that are typed as uppercase?
Create a Textbox key press handler and Use Path.GetInvalidPathChars()
, Path.GetInvalidFileNameChars()
to check for a valid char and return the uppercase version if the char is valid.
textBox1.CharacterCasing = CharacterCasing.Upper;
...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Path.GetInvalidFileNameChars().Contains(e.KeyChar) ||
Path.GetInvalidPathChars().Contains(e.KeyChar))
{
e.Handled = true;
}
}
[Of course, it would be more reusable to create a method rather than placing this code directly in the handler.]
UPDATED to reflect comments.