/// <summary> /// 循环卸载注册过的快捷键 /// </summary> private void Uninstall() { if (Resources.dicThisInt != null) { foreach (var item in Resources.dicThisInt) { SystemHotKey.UnregisterHotKey(Handle, item.Key); } } }
/// <summary> /// 获取路径文件,绑定列表数据,同步程序数据 /// </summary> /// <param name="flagReset">是否同步数据</param> private void BindingDgv(bool flagReset) { List <LnkModel> lnkList = new LnkPath().ListLnkModel(); if (lnkList == null) //有其它的文件 { DialogResult dr = MessageBox.Show("文件夹有非 lnk 文件!请修改路径或者删除非 lnk 文件。", "选择提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (dr == DialogResult.Cancel) { Application.Exit(); } if (dr == DialogResult.OK) { XmlFile.ChoiceLnkFile(); BindingDgv(false); } } foreach (LnkModel lnkModel in lnkList) { if (Resources.HandleDicThisInt(lnkModel.LnkName)) { if (Resources.HandleDicThis(lnkModel.LnkName)) { Resources.dicThis.Add(lnkModel.LnkName, lnkModel); } } } List <LnkModel> lnkListData = Resources.DicThisToLnkList(); if (flagReset) { List <LnkModel> lnkListString = new List <LnkModel>(); foreach (LnkModel item in lnkListData) //有的数据 { bool flag = true; foreach (var item2 in lnkList) //获取到的数据 { if (item.LnkName == item2.LnkName) { flag = false; } } if (flag) { lnkListString.Add(item); } } foreach (LnkModel item in lnkListString) { if (item.id == 0) //没有注册过 { Resources.dicThis.Remove(item.LnkName); } else { Resources.dicThisInt.Remove(item.id); SystemHotKey.UnregisterHotKey(Handle, item.id); } } dataGridView1.DataSource = lnkList; } if (lnkList.Count == 0) { try { Resources.dicThis.Clear(); Resources.dicThisInt.Clear(); } catch (Exception) { //throw; } lnkListData.Clear(); } dataGridView1.DataSource = lnkListData; //注册快捷键 Resources.RegistrationKey(Handle); }