Пример #1
0
        internal static string GetDisplayStringForCulture(IEnumerable <Key> keys, ModifierKeys modifiers, ITypeDescriptorContext context, CultureInfo culture)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            int numberOfKeys = keys.Count();

            if (numberOfKeys == 0 || (numberOfKeys == 1 && keys.First() == Key.None))
            {
                return(string.Empty);
            }

            var    result   = new StringBuilder();
            string firstKey = KeyConverter.ConvertTo(context, culture, keys.First(), typeof(string)) as string;

            if (!string.IsNullOrEmpty(firstKey))
            {
                string modifiersString = (string)ModifierKeysConverter.ConvertTo(context, culture, modifiers, typeof(string));
                bool   hasModifiers    = !string.IsNullOrEmpty(modifiersString);
                if (hasModifiers)
                {
                    result.Append(modifiersString);     // result = "Ctrl+Shift"
                    result.Append(ModifiersDelimiter);  // result = "Ctrl+Shift+"
                }

                result.Append(firstKey);                // result = "Ctrl+Shift+A"

                for (int i = 1; i < numberOfKeys; i++)
                {
                    string key = KeyConverter.ConvertTo(context, culture, keys.ElementAt(i), typeof(string)) as string;
                    if (!string.IsNullOrEmpty(key))
                    {
                        result.Append(KeysSeparator);   // result = "Ctrl+Shift+A,"
                        result.Append(' ');             // result = "Ctrl+Shift+A, "

                        if (hasModifiers)
                        {
                            result.Append(modifiersString);     // result = "Ctrl+Shift+A, Ctrl+Shift"
                            result.Append(ModifiersDelimiter);  // result = "Ctrl+Shift+A, Ctrl+Shift+"
                        }

                        result.Append(key);             // result = "Ctrl+Shift+A, Ctrl+Shift+B"
                    }
                }
            }

            return(result.ToString());
        }
        /// <summary>
        /// Evento ao digitar em um campo numerico
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ValueEdit_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter kv = new KeyConverter();

            if ((char.IsNumber((string)kv.ConvertTo(e.Key, typeof(string)), 0) == false) && e.Key.Equals(Key.OemPeriod))
            {
                e.Handled = true;
            }
        }
Пример #3
0
        /// <summary>
        /// Evento ao digitar em um campo numerico
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ValueEdit_KeyDown(object sender, KeyEventArgs e)
        {
            bool         handled = true;;
            KeyConverter kv      = new KeyConverter();

            if ((string.Compare((string)kv.ConvertTo(e.Key, typeof(string)), "OemComma") == 0))
            {
                if (!ValueEdit.Text.Contains(","))
                {
                    handled = false;
                }
            }
            else if ((char.IsNumber((string)kv.ConvertTo(e.Key, typeof(string)), 0)))
            {
                handled = false;
            }
            e.Handled = handled;
        }
Пример #4
0
        private void txbCelularUsuario_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter key = new KeyConverter();

            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
        }
Пример #5
0
        /// <summary>
        /// Evento ao digitar no campo de numero para bloquear caracteres
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void numberEdit_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter kv = new KeyConverter();

            if ((char.IsNumber((string)kv.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
        }
Пример #6
0
        private void txtCodigo_KeyDown(object sender, KeyEventArgs e)
        {
            //O CODIGO ABAIXO FORCA O TEXTBOX (txtCodigo) ACEITAR APENAS NUMEROS
            KeyConverter key = new KeyConverter();

            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
        }
Пример #7
0
            private bool IsTextChangingKey(Key key)
            {
                if (key >= Key.NumPad0 && key <= Key.NumPad9)
                {
                    return(true);
                }
                string keyString = (string)conv.ConvertTo(key, typeof(string));

                return(keyString.Length == 1);
            }
Пример #8
0
        /// <summary>
        ///   Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context"> An <see cref="System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
        /// <param name="culture"> A <see cref="System.Globalization.CultureInfo" /> . If null is passed, the current culture is assumed. </param>
        /// <param name="value"> The <see cref="object" /> to convert. </param>
        /// <param name="destinationType"> The <see cref="System.Type" /> to convert the <paramref name="value" /> parameter to. </param>
        /// <returns> An <see cref="object" /> that represents the converted value. </returns>
        /// <exception cref="System.ArgumentNullException">The
        ///   <paramref name="destinationType" />
        ///   parameter is null.</exception>
        /// <exception cref="System.NotSupportedException">The conversion cannot be performed.</exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                var gesture = value as MultiKeyGesture;

                if (gesture != null)
                {
                    var builder = new StringBuilder();

                    KeySequence sequence;

                    for (var i = 0; i < gesture.KeySequences.Length; i++)
                    {
                        if (i > 0)
                        {
                            builder.Append(", ");
                        }

                        sequence = gesture.KeySequences[i];
                        if (sequence.Modifiers != ModifierKeys.None)
                        {
                            builder.Append((string)modifierKeysConverter.ConvertTo(context, culture, sequence.Modifiers, destinationType));
                            builder.Append("+");
                        }

                        builder.Append((string)keyConverter.ConvertTo(context, culture, sequence.Keys[0], destinationType));

                        for (var j = 1; j < sequence.Keys.Length; j++)
                        {
                            builder.Append("+");
                            builder.Append((string)keyConverter.ConvertTo(context, culture, sequence.Keys[0], destinationType));
                        }
                    }

                    return(builder.ToString());
                }
            }

            throw GetConvertToException(value, destinationType);
        }
        private void TxbCNPJ_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter key = new KeyConverter();

            if (e.Key == Key.Tab)
            {
                return;
            }
            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
        }
        //TEXTBOX LOGIN SÓ ACEITAR NUMEROS E TAB
        private void tbLogin_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter key = new KeyConverter();

            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
            if (e.Key == Key.Tab)
            {
                tbSenha.Focus();
            }
        }
        private void Valor_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter key = new KeyConverter();

            if (new[] { Key.Tab, Key.OemComma }.Contains(e.Key))
            {
                return;
            }
            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
        }
Пример #12
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int          vk           = (int)((uint)value & ~(1 << 31));
            bool         shifted      = ((uint)value & (1 << 31)) != 0;
            Key          key          = KeyInterop.KeyFromVirtualKey(vk);
            KeyConverter keyConverter = new KeyConverter( );
            string       str          = (string)keyConverter.ConvertTo(key, typeof(string));

            if (shifted)
            {
                str = "Shift+" + str;
            }
            return(str);
        }
Пример #13
0
 private void TxtCPFCNPJ_KeyDown(object sender, KeyEventArgs e)
 {
     try
     {
         KeyConverter kv = new KeyConverter();
         if ((char.IsNumber((string)kv.ConvertTo(e.Key, typeof(string)), 0) == false))
         {
             e.Handled = true;
         }
     }
     catch (Exception er)
     {
         MessageBox.Show(er.Message);
     }
 }
Пример #14
0
        /// <inheritdoc />
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException(nameof(destinationType));
            }

            if (destinationType == typeof(string))
            {
                if (value != null)
                {
                    if (value is KeyGestureEx keyGesture)
                    {
                        if (keyGesture.Key == Key.None)
                        {
                            return(string.Empty);
                        }

                        var strBinding = string.Empty;
                        var strKey     = (string)keyConverter.ConvertTo(context, culture, keyGesture.Key, destinationType);
                        if (strKey != string.Empty)
                        {
                            strBinding += modifierKeysConverter.ConvertTo(context, culture, keyGesture.Modifiers, destinationType) as string;
                            if (strBinding != string.Empty)
                            {
                                strBinding += MODIFIERS_DELIMITER;
                            }

                            strBinding += strKey;

                            if (!string.IsNullOrEmpty(keyGesture.DisplayString))
                            {
                                strBinding += DISPLAYSTRING_SEPARATOR + keyGesture.DisplayString;
                            }
                        }

                        return(strBinding);
                    }
                }
                else
                {
                    return(string.Empty);
                }
            }

            throw this.GetConvertToException(value, destinationType);
        }
Пример #15
0
        //TEXTBOX ID PRODUTO SÓ ACEITAR NUMEROS E ENTER
        private void tbIDProduto_KeyDown(object sender, KeyEventArgs e)
        {
            KeyConverter key = new KeyConverter();

            if ((char.IsNumber((string)key.ConvertTo(e.Key, typeof(string)), 0) == false))
            {
                e.Handled = true;
            }
            if (e.Key == Key.Return)
            {
                btnPesquisar_Click(sender, e);
            }
            if (e.Key == Key.F5)
            {
                btnAtualizar_Click(sender, e);
            }
        }
Пример #16
0
        private void HandleKeyDownEvent(object sender, KeyEventArgs e)
        {
            var vm = (TestViewModel)DataContext;

//            if (e.Key == Key.E && (Keyboard.Modifiers & (ModifierKeys.Control | ModifierKeys.Shift)) == (ModifierKeys.Control | ModifierKeys.Shift))
            if (Keyboard.Modifiers.HasFlag(ModifierKeys.Control) &&
                !Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) &&
                !Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
            {
                var kc      = new KeyConverter();
                var charVal = (string)kc.ConvertTo(e.Key, typeof(string));
                if (charVal == null)
                {
                    return;
                }
                vm.DoCommand(charVal.ToCharArray()[0]);
                e.Handled = true;
            }
        }
        private bool IsTextChangingKey(Key key)
        {
            if (key == Key.Back || key == Key.Delete)
            {
                if (TargetControl.Text == "")
                {
                    this.listBox.SelectedItem = null;
                    this.popup.IsOpen         = false;
                }
                return(true);
            }
            else
            {
                KeyConverter conv      = new KeyConverter();
                string       keyString = (string)conv.ConvertTo(key, typeof(string));

                return(keyString.Length == 1);
            }
        }
Пример #18
0
        private static string getDisplayString(ModifierKeys modifiers, Key[] keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }
            if (keys.Length < 1)
            {
                throw new ArgumentException("keys must have at least one member");
            }
            StringBuilder ret = new StringBuilder();

            ret.Append(new KeyGesture(keys[0], modifiers).GetDisplayStringForCulture(CultureInfo.InvariantCulture));
            for (int i = 1; i < keys.Length; i++)
            {
                ret.Append(", ");
                ret.Append(_keyConverter.ConvertTo(null, CultureInfo.InvariantCulture, keys[i], typeof(string)));
            }
            return(ret.ToString());
        }
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == null)
     {
         throw new ArgumentNullException("destinationType");
     }
     if (destinationType == typeof(string))
     {
         if (value == null)
         {
             return(string.Empty);
         }
         UnrestrictedKeyGesture gesture = value as UnrestrictedKeyGesture;
         if (gesture != null)
         {
             if (gesture.Key == Key.None)
             {
                 return(string.Empty);
             }
             string str  = "";
             string str2 = (string)keyConverter.ConvertTo(context, culture, gesture.Key, destinationType);
             if (str2 != string.Empty)
             {
                 str = str + (modifierKeysConverter.ConvertTo(context, culture, gesture.Modifiers, destinationType) as string);
                 if (str != string.Empty)
                 {
                     str = str + '+';
                 }
                 str = str + str2;
                 if (!string.IsNullOrEmpty(gesture.DisplayString))
                 {
                     str = str + ',' + gesture.DisplayString;
                 }
             }
             return(str);
         }
     }
     throw base.GetConvertToException(value, destinationType);
 }
Пример #20
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                if (value == null)
                {
                    return(String.Empty);
                }

                if (value is KeyCombination combination)
                {
                    if (combination.Equals(KeyCombination.None))
                    {
                        return(String.Empty);
                    }
                    // convert key and modifiers to string
                    string keyString = keyConv.ConvertTo(context, culture, combination.Key, destinationType) as string;
                    string modString = modifiersConv.ConvertTo(context, culture, combination.Modifiers, destinationType) as string;
                    return(modString + DELIMITER + keyString);
                }
            }
            throw GetConvertToException(value, destinationType);
        }