示例#1
0
        private static void MenuItem_Click(object sender, EventArgs e)
        {
            KeyValuePair <string, string> pair = (KeyValuePair <string, string>)(sender as MenuItem).Tag;
            var    c        = Program.pluginManagment.Plugins.Find(x => x.appinfo.Name == pair.Key);
            string menuname = string.Empty;

            foreach (var item in JArray.Parse(c.json["menu"].ToString()))
            {
                if (item["name"].ToString() == pair.Value)
                {
                    menuname = item["function"].ToString(); break;
                }
            }
            menu = (Type_Menu)c.dll.Invoke(menuname, typeof(Type_Menu));
            menu();
        }
示例#2
0
        private static void MenuItem_Click(object sender, EventArgs e)
        {
            var targetItem = sender as MenuItem;

            try
            {
                switch (targetItem.Tag)
                {
                case "Quit":
                    Quit();
                    return;

                case "ReLoad":
                    MainForm.pluginManagment.ReLoad();
                    return;

                case "LogForm":
                    MainForm.CallLogForm();
                    return;

                case "Displaywindow":
                    if (targetItem.Checked)
                    {
                        targetItem.Checked = false;
                        MainForm.HideWindow();
                    }
                    else
                    {
                        targetItem.Checked = true;
                        MainForm.ShowWindow();
                    }
                    return;

                case "TopMost":
                    if (targetItem.Checked)
                    {
                        targetItem.Checked = false;
                        MainForm.TopMost_Disabled();
                    }
                    else
                    {
                        targetItem.Checked = true;
                        MainForm.TopMost_Enable();
                    }
                    return;
                }
                KeyValuePair <string, string> pair = (KeyValuePair <string, string>)(sender as MenuItem).Tag;
                PluginManagment.Plugin        c    = MainForm.pluginManagment.Plugins.Find(x => x.appinfo.Name == pair.Key);//从已加载的插件寻找这个名称的插件
                if (c.Enable is false)
                {
                    MessageBox.Show("插件未启用, 请打开菜单之前启用此插件", "无法调用菜单", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                string menuname = string.Empty;
                foreach (var item in JArray.Parse(JObject.Parse(c.json)["menu"].ToString()))//遍历此插件的json的menu节点,寻找窗口函数
                {
                    if (item["name"].ToString() == pair.Value)
                    {
                        menuname = item["function"].ToString(); break;
                    }
                }
                menu = (Type_Menu)c.dll.Invoke(menuname, typeof(Type_Menu)); //将函数转换委托
                menu();                                                      //调用
            }
            catch (Exception exc)
            {
                MessageBox.Show($"拉起菜单发生错误,错误信息:{exc.Message}\n{exc.StackTrace}", "菜单错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }