Beispiel #1
0
        public static void LoadCustomSettings()
        {
            RegistryKey rk = null;

            try
            {
                rk = Registry.CurrentUser.OpenSubKey(SubKey + "\\CustomUserSettings");
                if (rk == null)
                {
                    return;
                }
                System.Windows.Forms.KeysConverter converter = new System.Windows.Forms.KeysConverter();
                keyFullScreen       = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyFullScreen").ToString());
                keyNextMusic        = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyNextMusic").ToString());
                keyPlayPause        = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyPlayPause").ToString());
                keyPreviousMusic    = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyPreviousMusic").ToString());
                keyNextShift        = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyNextShift").ToString());
                keyPreviousShift    = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyPreviousShift").ToString());
                keyVolumeDown       = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyVolumeDown").ToString());
                keyVolumeUp         = (System.Windows.Forms.Keys)converter.ConvertFromString(rk.GetValue("KeyVolumeUp").ToString());
                defaultOffsetShift  = Convert.ToDouble(rk.GetValue("OffsetShift"));
                defaultOffsetVolume = Convert.ToInt32(rk.GetValue("OffsetVolume"));
                styleImage          = Convert.ToInt32(rk.GetValue("StyleImage"));
            }
            finally
            {
                if (rk != null)
                {
                    rk.Close();
                }
            }
        }
Beispiel #2
0
 public ControlBox(String s)
 {
     TextAnchor   = global::Graphics.Orientation.Center;
     keyConverter = new System.Windows.Forms.KeysConverter();
     if (s == "")
     {
         Key = System.Windows.Forms.Keys.None;
     }
     else
     {
         Key = (System.Windows.Forms.Keys)keyConverter.ConvertFromString(s);
     }
     Text      = s;
     AutoCheck = false;
 }
Beispiel #3
0
        private void WatermarkTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            TextBox textBox = (TextBox)sender;

            try
            {
                converter.ConvertFromString(e.Text.ToUpper());
                textBox.Text = string.Empty;
            }
            catch (Exception ex)
            {
                LogStatics.Debug(ex.ToString());
                e.Handled    = false;
                textBox.Text = string.Empty;
            }
        }
Beispiel #4
0
        private void ResetButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("You can not reverse this, do you want to continue?", "WARNING!", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                Properties.Settings.MyKeyBinds.SetInput(KeyRefrence, Properties.Settings.MyDefaultKeyBinds.GetInput(KeyRefrence));

                Classes.Options.InputPreferences.Save();
                Classes.Options.InputPreferences.Reload();
                KeysConverter kc = new KeysConverter();
                CurrentBindingKey = (Keys)kc.ConvertFromString(KeyBindsList[ListIndex].ToString());

                UpdateResultLabel();
                SetupExistingKeybinds(KeyRefrence);
                SetupListBox();
            }
        }
Beispiel #5
0
        private int GetKeys()
        {
            //获得组合键值string
            string strKeys = this.txtKey.Text.Trim();

            //检查是否为空
            if (!string.IsNullOrEmpty(strKeys))
            {
                System.Windows.Forms.KeysConverter keyCvt = new System.Windows.Forms.KeysConverter();

                //合法标志置否
                this.Available = false;

                //转全小写
                strKeys = strKeys.ToLower();

                //声明键状态
                bool Ctrl  = false;
                bool Alt   = false;
                bool Shift = false;
                System.Windows.Forms.Keys key = System.Windows.Forms.Keys.None;

                //检查是否包含Ctrl
                if (strKeys.IndexOf("ctrl") >= 0)
                {
                    Ctrl    = true;
                    strKeys = strKeys.Replace("ctrl+", "");
                }

                //检查是否包含Alt
                if (strKeys.IndexOf("alt") >= 0)
                {
                    Alt     = true;
                    strKeys = strKeys.Replace("alt+", "");
                }

                //检查是否包含Shift
                if (strKeys.IndexOf("shift") >= 0)
                {
                    Shift   = true;
                    strKeys = strKeys.Replace("shift+", "");
                }

                //确保字符串不包含空格
                strKeys = strKeys.Trim();

                //检查是否为空,此步骤非必要,为了健壮加上
                if (!string.IsNullOrEmpty(strKeys))
                {
                    //从字符串转换键值

                    key = (System.Windows.Forms.Keys)keyCvt.ConvertFromString(strKeys.ToUpper());
                }

                //最后检查合法性
                //至少一个Key + 一种控制键
                if (key != System.Windows.Forms.Keys.None && (Ctrl || Alt || Shift))
                {
                    this.KeyValue = key;

                    if (Ctrl && !Alt && !Shift) //Ctrl + Key
                    {
                        this.ModifiersValue = (uint)HotKey.KeyModifiers.Ctrl;
                    }
                    else if (Ctrl && Alt && !Shift) //Ctrl + Alt + Key
                    {
                        this.ModifiersValue = (uint)HotKey.KeyModifiers.Ctrl | (uint)HotKey.KeyModifiers.Alt;
                    }
                    else if (Ctrl && Alt && Shift) //Ctrl + Alt + Shift + Key
                    {
                        this.ModifiersValue = (uint)HotKey.KeyModifiers.Ctrl | (uint)HotKey.KeyModifiers.Alt | (uint)HotKey.KeyModifiers.Shift;
                    }
                    else if (!Ctrl && Alt && Shift) // Alt + Shift + Key
                    {
                        this.ModifiersValue = (uint)HotKey.KeyModifiers.Alt | (uint)HotKey.KeyModifiers.Shift;
                    }
                    else if (!Ctrl && !Alt && Shift) //Shift + Key
                    {
                        this.ModifiersValue = (uint)HotKey.KeyModifiers.Shift;
                    }
                    else //非法组合件
                    {
                        this.Available        = false;
                        this.KeyValue         = System.Windows.Forms.Keys.None;
                        this.ModifiersValue   = 0;
                        this.bdrAC.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                        return(-1);
                    }
                }
                else
                {
                    //非法
                    this.Available        = false;
                    this.bdrAC.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                    this.KeyValue         = System.Windows.Forms.Keys.None;
                    this.ModifiersValue   = 0;
                    return(-1);
                }

                this.Available = true;

                if (HotKey.TestHotKey(this.ModifiersValue, this.KeyValue))
                {
                    this.bdrAC.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Green);
                }
                else
                {
                    this.bdrAC.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
                }
                return(0);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 从数据文件路径初始化内部数据
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private int ConnectDB()
        {
            if (objDB != null)
            {
                this.data.Name = objDB.ReadFirstByName("Name") as string;
                this.data.ID   = objDB.ReadFirstByName("ID") as string;
                int Count = Convert.ToInt32(objDB.ReadFirstByName("Icon"));

                try
                {
                    using (BinaryReader br = new BinaryReader(new FileStream(Manage.IconPath + data.ID + ".ib", FileMode.Open)))
                    {
                        data.Icon = br.ReadBytes(Count);
                    }

                    data.IS = GetIcon.ByteArrayToIS(data.Icon);
                }
                catch
                {
                }

                this.data.Path             = objDB.ReadFirstByName("Path") as string;
                this.data.Arguments        = objDB.ReadFirstByName("Arguments") as string;
                this.data.RunAs            = Convert.ToInt32(objDB.ReadFirstByName("Runas"));
                this.data.AutoRun          = Convert.ToInt32(objDB.ReadFirstByName("Autorun"));
                this.data.Levels           = Convert.ToInt32(objDB.ReadFirstByName("Levels"));
                this.data.WorkingDirectory = objDB.ReadFirstByName("WorkingDirectory");
                this.data.tagName          = objDB.ReadFirstByName("TagName");

                string strHKI = objDB.ReadFirstByName("HotKey");

                if (strHKI != null)
                {
                    if (!string.IsNullOrEmpty(strHKI.Replace(",", "").Replace(" ", "")))
                    {
                        string[] HKISplit;
                        try
                        {
                            HKISplit = strHKI.Split(',');
                        }
                        catch
                        {
                            HKISplit = new string[] { };
                        }
                        if (HKISplit.Length >= 3)
                        {
                            System.Windows.Forms.KeysConverter keyCvt = new System.Windows.Forms.KeysConverter();

                            this.data.HotKey = new HotKeyItem(this, (System.Windows.Forms.Keys)keyCvt.ConvertFromString(HKISplit[0]), Convert.ToUInt32(HKISplit[1]), Convert.ToInt32(HKISplit[2]), HotKeyItem.HotKeyParentType.Item);

                            if (Manage.CheckAndRegisterHotKey(data.HotKey))
                            {
                                Anything_wpf_main_.cls.HotKey.CurrentID++;
                                data.EnableHotKey = true;
                            }
                        }
                        else
                        {
                            this.data.HotKey = new HotKeyItem(null, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item);
                        }
                    }
                    else
                    {
                        data.HotKey = new HotKeyItem(this, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item);
                    }
                }

                return(0);
            }
            return(-1);
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (chbAutoLogon.IsChecked.HasValue)
            {
                Settings.Default.AutoLogon = chbAutoLogon.IsChecked.Value;
            }

            if (chbAutoStart.IsChecked.HasValue)
            {
                Settings.Default.AutoStart = chbAutoStart.IsChecked.Value;
                AutoStart.Current.EnabledThroughStartupMenu = chbAutoStart.IsChecked.Value;
            }

            if (chbAlwaysInTray.IsChecked.HasValue)
            {
                Settings.Default.AlwaysInTray = chbAlwaysInTray.IsChecked.Value;
            }

            if (chbMinimalizeToTray.IsChecked.HasValue)
            {
                Settings.Default.MinimalizeToTray = chbMinimalizeToTray.IsChecked.Value;
            }

            if (chbPlaySoundWhenNewStatus.IsChecked.HasValue)
            {
                Settings.Default.PlaySoundWhenNewStatus = chbPlaySoundWhenNewStatus.IsChecked.Value;
            }

            if (chbHotKeyEnabled.IsChecked.HasValue)
            {
                Settings.Default.HotKeyEnabled = chbHotKeyEnabled.IsChecked.Value;
            }

            System.Windows.Forms.KeysConverter keysConverter = new System.Windows.Forms.KeysConverter();
            Settings.Default.HotKey = (System.Windows.Forms.Keys)keysConverter.ConvertFromString(HotKeyComboBox.SelectedItem.ToString());

            Settings.Default.Save();
            Close();
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(converter.ConvertFromString((string)value));
 }
Beispiel #9
0
        static public System.Windows.Forms.Keys KeyFromString(string str)
        {
            var kc = new System.Windows.Forms.KeysConverter();

            return((System.Windows.Forms.Keys)kc.ConvertFromString(str));
        }
Beispiel #10
0
        public override void TriggerApply()
        {
            System.Windows.Forms.KeysConverter a = new System.Windows.Forms.KeysConverter();
            int i = 0;

            foreach (var v in typeof(PublicControlsSettings).GetProperties())
            {
                var a1 = Attribute.GetCustomAttributes(v, false);
                foreach (ControlsAttribute c in a1)
                {
                    string text = textBoxes[i++].Text;
                    if (text == "")
                    {
                        v.SetValue(Program.ControlsSettings, System.Windows.Forms.Keys.None, null); // textBoxes[i].Key, null);
                    }
                    else
                    {
                        v.SetValue(Program.ControlsSettings, (System.Windows.Forms.Keys)a.ConvertFromString(text), null);
                    }
                }
            }
        }