コード例 #1
0
        /// <summary>
        /// Highlights rich text box with simple setting definition string.
        /// </summary>
        public static void HighlightSimpleSetting(
            RichTextBox rich,
            ITextValidator textValidator,
            ICharValidator charValidator)
        {
            if (textValidator.IsValidText(rich.Text))
            {
                rich.ResetBackColor();
            }
            else
            {
                rich.BackColor = Colors.LightRed;
            }

            int current = 0;

            foreach (string line in rich.Lines)
            {
                for (int i = 0; i < line.Length; i++)
                {
                    if (!charValidator.IsValidChar(line[i]))
                    {
                        rich.SelectionStart  = current + i;
                        rich.SelectionLength = 1;
                        rich.SelectionColor  = Color.Red;
                    }
                }

                current += line.Length + 1;
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks if specified text can describe a simple setting.
        /// </summary>
        public static bool CheckSimpleSetting(string text, ICharValidator validator)
        {
            foreach (char c in text)
            {
                if (!validator.IsValidChar(c))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Highlights rich text box with simple setting definition string.
        /// </summary>
        public static void HighlightSimpleSetting(
            RichTextBox rich,
            ITextValidator textValidator,
            ICharValidator charValidator)
        {
            if (textValidator.IsValidText(rich.Text))
            {
                rich.ResetBackColor();
            }
            else
            {
                rich.BackColor = Colors.LightRed;
            }

            int current = 0;
            foreach (string line in rich.Lines)
            {
                for (int i = 0; i < line.Length; i++)
                {
                    if (!charValidator.IsValidChar(line[i]))
                    {
                        rich.SelectionStart = current + i;
                        rich.SelectionLength = 1;
                        rich.SelectionColor = Color.Red;
                    }
                }

                current += line.Length + 1;
            }
        }
コード例 #4
0
        /// <summary>
        /// Checks if specified text can describe a simple setting.
        /// </summary>
        public static bool CheckSimpleSetting(string text, ICharValidator validator)
        {
            foreach (char c in text)
            {
                if (!validator.IsValidChar(c))
                    return false;
            }

            return true;
        }