有一个 windform 程序,上面有一个 ComboBox ,我希望在它的 SelectedIndexChanged 事件里绑定一个叫 "Test" 的方法。大体是这样的过程,有一个 Bind(string methodName) 方法,通过传入的 "Test" 这个字符串利用反射找到此方法,然后添加在 ComboBox 的 SelectedIndexChanged 事件上。请问具体怎么写,我已经写过几次了,不成功。

解决方案 »

  1.   

       Control _ComboBox = this.Controls["comboBox1"];            System.Reflection.MethodInfo _IndexChangedInfo = this.GetType().GetMethod("Test");
                Delegate _IndexChanged = Delegate.CreateDelegate(typeof(EventHandler), this, _IndexChangedInfo);            _ComboBox.GetType().GetEvent("SelectedIndexChanged").AddEventHandler(_ComboBox, _IndexChanged);