當前位置: 首頁>>代碼示例>>C#>>正文


C# KeysConverter.ConvertFrom方法代碼示例

本文整理匯總了C#中System.Windows.Forms.KeysConverter.ConvertFrom方法的典型用法代碼示例。如果您正苦於以下問題:C# KeysConverter.ConvertFrom方法的具體用法?C# KeysConverter.ConvertFrom怎麽用?C# KeysConverter.ConvertFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Forms.KeysConverter的用法示例。


在下文中一共展示了KeysConverter.ConvertFrom方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: set_hotkey

        public void set_hotkey(string hotkey_string)
        {
            var cvt = new KeysConverter();
            var key = (Keys)cvt.ConvertFrom(hotkey_string);

            ModifierKeys mk = SkipDonation.ModifierKeys.None;

            if (key.HasFlag(Keys.Control))
            {
                mk |= SkipDonation.ModifierKeys.Control;
                key = key & (~Keys.Control);
            }

            if (key.HasFlag(Keys.Alt))
            {
                mk |= SkipDonation.ModifierKeys.Alt;
                key = key & (~Keys.Alt);
            }

            if (key.HasFlag(Keys.Shift))
            {
                mk |= SkipDonation.ModifierKeys.Shift;
                key = key & (~Keys.Shift);
            }

            hook.RegisterHotKey(mk, key);
            lbl_hotkey.Text = hotkey_string;
        }
開發者ID:pajlada,項目名稱:SkipDonation,代碼行數:28,代碼來源:MainForm.cs

示例2: ParseShortcut

        /// <summary>Parses a shortcut string like 'Control + Alt + Shift + V' and returns the key and modifiers.
        /// </summary>
        /// <param name="text">The shortcut string to parse.</param>
        /// <returns>The Modifier in the lower bound and the key in the upper bound.</returns>
        public static object[] ParseShortcut(string text)
        {
            bool HasAlt = false; bool HasControl = false; bool HasShift = false; bool HasWin = false;

            Modifiers Modifier = Modifiers.None;		//Variable to contain modifier.
            Keys key = 0;           //The key to register.
            int current = 0;

            string[] result;
            string[] separators = new string[] { " + " };
            result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //Iterate through the keys and find the modifier.
            foreach (string entry in result)
            {
                //Find the Control Key.
                if (entry.Trim() == Keys.Control.ToString())
                {
                    HasControl = true;
                }
                //Find the Alt key.
                if (entry.Trim() == Keys.Alt.ToString())
                {
                    HasAlt = true;
                }
                //Find the Shift key.
                if (entry.Trim() == Keys.Shift.ToString())
                {
                    HasShift = true;
                }

                //Find the Window key.
                if (entry.Trim() == Keys.LWin.ToString() && current != result.Length - 1)
                {
                    HasWin = true;
                }

                current++;
            }

            if (HasControl) { Modifier |= Modifiers.Control; }
            if (HasAlt) { Modifier |= Modifiers.Alt; }
            if (HasShift) { Modifier |= Modifiers.Shift; }
            if (HasWin) { Modifier |= Modifiers.Win; }

            KeysConverter keyconverter = new KeysConverter();
            key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));

            return new object[] { Modifier, key };
        }
開發者ID:modulexcite,項目名稱:HotKey-Manager-for-WinForm-and-WPF-Apps,代碼行數:54,代碼來源:Helpers.cs

示例3: GetKeysFromString

        private static Keys GetKeysFromString(string keys)
        {
            var converter = new KeysConverter();
            var keySequence = converter.ConvertFrom(null, CultureInfo.CurrentCulture, keys);
            if (keySequence != null)
            {
                return (Keys)keySequence;
            }

            return Keys.None;
        }
開發者ID:codito,項目名稱:oshell,代碼行數:11,代碼來源:DefinekeyCommandTests.cs

示例4: GenerateSubMenuItem

        private void GenerateSubMenuItem(PluginLoader pluginLoader, ToolStripMenuItem parentMenuItem, Menu menu)
        {
            foreach(Menu mm in menu.SubMenus)
            {
                ToolStripMenuItem menuItem = new ToolStripMenuItem(mm.Name);

                // add image menu item
                if (mm.Image != null)
                    menuItem.Image = Image.FromStream(new MemoryStream(mm.Image));

                // add shorcut menu item
                menuItem.ShowShortcutKeys = true;
                if (mm.ShortcutKey != null)
                {
                    menuItem.ShortcutKeyDisplayString = mm.ShortcutKey;
                    KeysConverter cvt = new KeysConverter();

                    menuItem.ShortcutKeys = (Keys)cvt.ConvertFrom(mm.ShortcutKey);
                }

                // add handler click menu item
                if (mm.Type == Convert.ToInt32(MenuType.COMMAND))
                {
                    // asociate plugin instance assembly
                    mm.Assembly = pluginLoader.LoadAndRun(mm.AssemblyName, mm.AssemblyVersion, mm.Image);

                    menuItem.Tag = mm;
                    menuItem.Click += new EventHandler(PluginHandler_Click);
                }

                parentMenuItem.DropDownItems.Add(menuItem);

                if (mm.Type == Convert.ToInt32(MenuType.MENU))
                    GenerateSubMenuItem(pluginLoader, menuItem, mm);
            }
        }
開發者ID:masalinas,項目名稱:konekti.net,代碼行數:36,代碼來源:MainView.cs

示例5: UpdateCustomShortcut

        void UpdateCustomShortcut(string text)
        {
            LogEvents("Attempting to update custom shortcut to: " + text);

            //Will help determine if the shortcut has any modifier.
            bool HasAlt = false; bool HasControl = false; bool HasShift = false;

            Modifiers Modifier = Modifiers.None;		//Variable to contain modifier.
            Keys key = 0;           //The key to register.

            string[] result;
            string[] separators = new string[] { " + " };
            result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //Iterate through the keys and find the modifier.
            foreach (string entry in result)
            {
                //Find the Control Key.
                if (entry.Trim() == Keys.Control.ToString())
                {
                    HasControl = true;
                }
                //Find the Alt key.
                if (entry.Trim() == Keys.Alt.ToString())
                {
                    HasAlt = true;
                }
                //Find the Shift key.
                if (entry.Trim() == Keys.Shift.ToString())
                {
                    HasShift = true;
                }
            }

            if (HasControl) { Modifier |= Modifiers.Control; }
            if (HasAlt) { Modifier |= Modifiers.Alt; }
            if (HasShift) { Modifier |= Modifiers.Shift; }

            //Get the last key in the shortcut
            KeysConverter keyconverter = new KeysConverter();
            key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));

            ghkCustom.Enabled = chkCustomEnabled.Checked;
            ghkCustom.Key = key;
            ghkCustom.Modifier = Modifier;

            LogEvents(string.Format("Custom shortcut updated. \n Key:{0}, Modifier:{1}", ghkCustom.Key, ghkCustom.Modifier));
        }
開發者ID:modulexcite,項目名稱:HotKey-Manager-for-WinForm-and-WPF-Apps,代碼行數:48,代碼來源:AppStarter.cs


注:本文中的System.Windows.Forms.KeysConverter.ConvertFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。