private void RecipeName_TextBox_KeyUp(object sender, KeyEventArgs e)
        {
            // Since Recipe Names are used to make file names make the sure user doesnt input invalid file format
            char[] InvalidCharacter = new char[] { '<', '>', ':', '"', '/', '\\', '|', '?', '*', '\'', '.', ',', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '`', '~', ';', '[', ']', '{', '}' };

            // Iterate through the text box to check for invalid characters
            foreach (var item in RecipeName_TextBox.Text)
            {
                for (int i = 0; i < InvalidCharacter.Length; i++)
                {
                    if (item == InvalidCharacter[i])
                    {
                        // Play windows error sound if invalid key is pressed
                        System.Media.SystemSounds.Hand.Play();
                        RecipeName_TextBox.Clear();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void RecipeName_TextBox_KeyUp(object sender, KeyEventArgs e)
        {
            // Limit the user from entering invalid characters into the Recipe Name field
            // This is a list of all illegal characters
            char[] InvalidCharacter = new char[] { '<', '>', ':', '"', '/', '\\', '|', '?', '*', '\'', '.', ',', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '`', '~', ';', '[', ']', '{', '}' };

            // Iterate through the text box to check for invalid characters
            foreach (var item in RecipeName_TextBox.Text)
            {
                for (int i = 0; i < InvalidCharacter.Length; i++)
                {
                    if (item == InvalidCharacter[i])
                    {
                        // Play windows error sound if invalid key is pressed
                        System.Media.SystemSounds.Hand.Play();
                        RecipeName_TextBox.Clear();
                    }
                }
            }
        }