/// <summary>
 /// 菜单退出按钮事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MenuExit(object sender, EventArgs e)
 {
     hi.Close();
     loading.Close();
     this.RegisterAppBar(true);
     Application.Exit();
 }
Пример #2
0
        /// <summary>
        /// 添加命令按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addProgram_Click(object sender, EventArgs e)
        {
            String command;

            command = Command.Text.Substring(Command.Text.LastIndexOf('+') + 1);
            LoadConfig writeConfig;
            String     rule = @"[A-Z0-9,./;'\[\\=]|]|-";
            Match      m    = Regex.Match(command, rule);

            if (!m.Success)
            {
                MessageBox.Show("Space+后面的字符必须为A-Z0-9,./;'[]\\-=字符中的一个");
                return;
            }
            //将;[=进行特殊处理
            switch (command)
            {
            case ";":
                command = "sm";
                break;

            case "[":
                command = "lb";
                break;

            case "=":
                command = "eq";
                break;

            default:
                break;
            }
            switch (resourceType.SelectedIndex)
            {
            case 0:
                String fileName = program.FileName;
                if (command.Trim() == "")
                {
                    hi.setHint("请输入指令!");
                    hi.Show();
                    return;
                }
                if (fileName == "")
                {
                    hi.setHint("请选择程序!");
                    hi.Show();
                    return;
                }
                writeConfig = new LoadConfig(Application.StartupPath + @"\command.ini");
                if (args.Text.Trim() != "")
                {
                    fileName += "?" + args.Text.Trim();
                }
                if (resource.Text != "选择文件" && resource.Text.Trim() != "")
                {
                    if (args.Text.Trim() == "")
                    {
                        fileName += "?" + resource.Text.Trim();
                    }
                    else
                    {
                        fileName += " " + resource.Text.Trim();
                    }
                }
                if (writeConfig.ReadIni("Command List", command) != "")
                {
                    DialogResult dr = MessageBox.Show(command + "热键已存在,是否覆盖?", "咒语记混了吗?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        writeConfig.IniWriteValue("Command List", command.Trim(), fileName);
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                    }
                }
                else
                {
                    writeConfig.IniWriteValue("Command List", command.Trim(), fileName);
                }
                hi.Close();
                Close();
                break;

            case 1:
                String folderName = "explorer.exe?" + folder.Text;
                if (command.Trim() == "")
                {
                    hi.setHint("请输入指令!");
                    hi.Show();
                    return;
                }
                if (folder.Text.Trim() == "")
                {
                    hi.setHint("请选择文件夹!");
                    hi.Show();
                    return;
                }
                writeConfig = new LoadConfig(Application.StartupPath + @"\command.ini");
                if (writeConfig.ReadIni("Command List", command) != "")
                {
                    DialogResult dr = MessageBox.Show(command + "热键已存在,是否覆盖?", "咒语记混了吗?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        writeConfig.IniWriteValue("Command List", command.Trim(), folderName);
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                    }
                }
                else
                {
                    writeConfig.IniWriteValue("Command List", command.Trim(), folderName);
                }
                hi.Close();
                Close();
                break;

            case 2:
                String url = webSite.Text;
                if (url.Trim() == "")
                {
                    hi.setHint("请输入URL!");
                    hi.Show();
                    return;
                }
                if (!url.Contains(":"))
                {
                    MessageBox.Show(url + "URL格式错误!请加上协议头。");
                    return;
                }
                String site = "explorer.exe?" + url;
                if (command.Trim() == "")
                {
                    hi.setHint("请输入指令!");
                    hi.Show();
                    return;
                }

                writeConfig = new LoadConfig(Application.StartupPath + @"\command.ini");
                if (writeConfig.ReadIni("Command List", command) != "")
                {
                    DialogResult dr = MessageBox.Show(command + "热键已存在,是否覆盖?", "咒语记混了吗?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        writeConfig.IniWriteValue("Command List", command.Trim(), site);
                    }
                    else if (dr == DialogResult.Cancel)
                    {
                    }
                }
                else
                {
                    writeConfig.IniWriteValue("Command List", command.Trim(), site);
                }
                hi.Close();
                Close();
                break;

            default:
                MessageBox.Show("请选择类型!");
                break;
            }
        }