大家好,我是赤道上的小熊,最近在做一个二开设计平台,要实现遍历某EXE中的所有窗体以及窗体上的控件,下面的实现方式不仅可以找到窗体中已经存在的控件,通过程序动态创建的控件也可以遍历到(例如:Button button2 = new Button()),希望对大家所有帮助。
- PS:该实现方式必须和要寻找的窗体在同一项目中
//获取EXE中的控件值
string strRes = "";
private void GetControls()
{
strRes = "";
System.Reflection.Assembly ase = System.Reflection.Assembly.LoadFile(Application.ExecutablePath);//.net中的反射 Application.ExecutablePath exe所在路径
Type[] types = ase.GetTypes()