コード例 #1
0
        /// <summary>
        /// Parses a string as an <see cref="XMouseButtonCombo"/> value using the specified <see cref="CultureInfo"/>.
        /// </summary>
        /// <param name="s">The string to be parsed.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> for which the string should be parsed.</param>
        /// <param name="result">The <see cref="XMouseButtonCombo"/> value parsed from <paramref name="s"/>.</param>
        /// <returns>True if the string was successfully parsed; False otherwise.</returns>
        public static bool TryParse(string s, CultureInfo culture, out XMouseButtonCombo result)
        {
            if (string.IsNullOrEmpty(s))
            {
                result = None;
                return(true);
            }

            XMouseButtons mouseButtons;

            if (XMouseButtonsConverter.TryParse(s, culture, out mouseButtons))
            {
                result = new XMouseButtonCombo(mouseButtons);
                return(true);
            }

            if (s.Length > 1)
            {
                // we want trailing and leading separators to fail the conversion
                int lastIndex = s.Length - 1;
                while ((lastIndex = s.LastIndexOf(XMouseButtonsConverter.ButtonSeparator, lastIndex - 1)) > 0)
                {
                    ModifierFlags modifiers;
                    if (XMouseButtonsConverter.TryParse(s.Substring(lastIndex + 1), culture, out mouseButtons) &&
                        ModifierFlagsConverter.TryParse(s.Substring(0, lastIndex), culture, out modifiers))
                    {
                        result = new XMouseButtonCombo(mouseButtons, modifiers);
                        return(true);
                    }
                }
            }

            result = None;
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Formats the mouse button combination as a string using the specified <see cref="CultureInfo"/>.
        /// </summary>
        /// <param name="culture">The <see cref="CultureInfo"/> for which the value should be formatted.</param>
        /// <returns>The string representation of the mouse button combination.</returns>
        public string ToString(CultureInfo culture)
        {
            string mouseButtons = XMouseButtonsConverter.Format(MouseButtons, culture);

            if (Modifiers != ModifierFlags.None && MouseButtons != XMouseButtons.None)
            {
                return(string.Format("{0}{1}{2}", ModifierFlagsConverter.Format(Modifiers, culture), XMouseButtonsConverter.ButtonSeparator, mouseButtons));
            }
            return(mouseButtons);
        }