tags:

views:

50

answers:

2

Is there an easy way for this?

  1. About the set of characters allowed in a Windows file system (Char.IsLetterOrDigit is not enough)

  2. How do I make the characters that are typed as uppercase?

+2  A: 

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.

Mitch Wheat
This. Plus one...
Pierreten
e.KeyChar = Char.ToUpper(e.KeyChar); doesn't work though. I used the CharacterCasing property from the previous reply.
Joan Venge