private void InitBotModules() { try { var saved = XmlUtil.LoadXML(Application.StartupPath + "/bot_modules.save"); if (saved != null) { var cfg = XmlUtil.XmlToObject <BotModulesConfig>(saved); foreach (var me in cfg.Modules) { var mt = ReflectionUtil.GetType(me.Key); if (mt != null) { BotModule.SetModuleEnable(mt, me.Value); } } } } catch (Exception err) { MessageBox.Show(err.Message); } foreach (var mt in BotFactory.Instance.GetModuleTypes()) { var enable = BotModule.GetModuleEnable(mt); var item = new ToolStripMenuItem(); item.CheckOnClick = true; item.Size = new System.Drawing.Size(152, 22); item.Text = "模块:" + mt.Name; item.Tag = mt; item.Checked = enable; item.CheckedChanged += moduleItem_CheckedChanged; group_Module.DropDownItems.Add(item); } }
private void moduleItem_CheckedChanged(object sender, EventArgs e) { var item = sender as ToolStripMenuItem; var mt = item.Tag as Type; BotModule.SetModuleEnable(mt, item.Checked); SaveBotModules(); }