当前位置: 首页>>代码示例>>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;未经允许,请勿转载。