Button b = new Button() ;
Type t = b.GetType() ;
Type t = b.GetType() ;
解决方案 »
- MEF 多对象、动态管理思路??
- 在线等待,请各位帮帮忙
- 顶者有分, 滚动条联动的问题 ,我有二个控件,分别为DataGridView 和Panel ,现在要求DataGridView 的纵向滚动条和Panel的纵向滚动条联动,
- devexpress的VGridControl控件中EditValueChanged事件的获取被包装的RepositoryItem
- 求c#面向对象的程序设计的电子版
- JS获取用户控件值的问题
- 怎么得到指定路径的.exe文件的ico图片
- 大家好,我再 SQL 搜索中如何排除已经 不符合的 记录啊?
- threadpool请教
- DataGrid1中嵌套了一个子DataGrid2,这个DataGrid2怎么分页?
- 请问如何将数据库表的一条记录中的一项赋值给一个变量
- 千古奇遇,DataGrid设置了Dock属性后,窗口最小化后无法重新绑定数据,谁能解决?
b.Parent= this;
if (o is Button) //不是button
{
Control c = (Control)o;
this.Controls.Add(c);
}
我想可能是GetType的限制吧查了一下帮助,可是不懂什么意思GetType 仅适用于从磁盘加载的程序集。如果调用 GetType 来查找在用 System.Reflection.Emit 服务定义的动态程序集中定义的类型,则可能会获得不一致的行为。行为取决于动态程序集是否持久,即是否使用 System.Reflection.Emit.AssemblyBuilderAccess 枚举的 RunAndSave 或 Save 访问模式来创建。如果动态程序集持久并已在调用 GetType 之前写入磁盘,则加载器会在磁盘上查找已保存的程序集,加载该程序集并从该程序集中检索类型。如果在调用 GetType 时程序集尚未保存到磁盘中,则此方法返回空引用(Visual Basic 中为 Nothing)。GetType 不识别瞬态动态程序集,因此通过调用 GetType 来检索瞬态动态程序集中的类型将返回空引用 (Nothing)。
Assembly asm = Assembly.LoadWithPartialName("System.Windows.Forms");Type t = typeof(System.Windows.Forms.Button); //t值不为nullobject o = Activator.CreateInstance(t);
只需要在GetType参数里指明定义Button的Assembly。Type t = Type.GetType("System.Windows.Forms.Button, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
or in your program, Assembly.FullName.