由于修改了参数配置的实现,Debug Console 中加载配置参数会出现问题,因此需要修改相应的逻辑实现。
实现思路
在 onload () 事件中(执行 onload 的时候所有插件都已经完成初始化 init (),所以会在对应的 Attributes 中包含需要保存的参数),读取主程序和各个插件的 Attributes,然后找出 bool 类型的变量,将其加入到开关字典 switches<string,object > 中,并且根据读取到的变量列表 l_MainWnd、l_cfg、l_plugin 来生成 checkbox 控件,最后定义其点击事件,在事件中将对应键值与 checkbox 的 Checked 属性进行绑定,最终实现点击选择框修改对应的变量。
该思路的核心部分在于读入插件参数并创建控件的过程,其实现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| private void CreateContorls(Form f) { switches = new Dictionary<string, object>();
cBoxs = new List<CheckBox>();
List<string> l_MainWnd = new List<string>(); List<string> l_cfg = new List<string>();
object cfg = Toolkits.GetValue(MainWnd, "cfg");
Dictionary<string, object> MainParam = (Dictionary<string, object>)Toolkits.getObj(MainWnd, "Attributes"); Dictionary<string, object> cfgParam = (Dictionary<string, object>)Toolkits.getObj(cfg, "Parameters");
foreach (IPlugin plugin in plugins) { if (plugin.Attributes != null && !plugin.Equals(this)) { List<string> l_plugin = new List<string>(); GetBooleanValues(plugin.Attributes, ref l_plugin); ...; } }
GetBooleanValues(MainParam, ref l_MainWnd); GetBooleanValues(cfgParam, ref l_cfg); foreach (string key in l_MainWnd) { ...; }
foreach (string key in l_cfg) { ...; } ...; }
|
OnLoad 中的对应流程 (其他无关部分省略):
1 2 3 4 5 6 7 8 9 10 11 12 13
| OnLoad() { ...; logo.Click += new EventHandler((object sender, EventArgs ea) => { ...; CreateContorls(form); ...; });
}
|
最终结果


左侧的控件就是在这个过程中自动装填生成的。