如何用Type(反射)来遍历某个控件(以TextBox为例)的所有的属性或事件或方法的名称???
哪位朋友可以给个可以执行的代码。
msdn上搜过了,只给出了Console下的例子,而在WINFORM中却不执行了,哪位朋友对反射熟悉???
书上关于这方面的例子极少,
多谢指教!!!!!!!!!!!!!!!!!!!!!!!!!!!
哪位朋友可以给个可以执行的代码。
msdn上搜过了,只给出了Console下的例子,而在WINFORM中却不执行了,哪位朋友对反射熟悉???
书上关于这方面的例子极少,
多谢指教!!!!!!!!!!!!!!!!!!!!!!!!!!!
解决方案 »
- 字符串转换格式不对
- 构造函数的参数可以是函数所在的类?
- C#线程函数中无法设置断点单步执行
- C# 中 如何使用存储过程
- 完成剪切、复制、粘贴的功能;完成全选的功能;完成窗口的排列功能
- javascript的一个问题
- 怎么样实现"颜色下拉comboBox"?
- 经过几天别扭的调试,发现我的问题出在了MDI上,由于不能上传文件,详情请进来,谢谢
- 请问vs2005中用C#调用C++的DLL怎么做呀
- 请问<<Visual C# 入门经典>>与<< C# 入门经典>>有什么区别???
- ********新手提个小问题*********
- 跪求: winform 高手。自定窗口, FormBorderStyle = none 的问题。困扰N久了
{
Console.WriteLine("属性列表-----------------------");
Type t=typeof(System.Windows.Forms.Button);
PropertyInfo[] p=t.GetProperties();
foreach(PropertyInfo i in p)
{
Console.WriteLine(i);
}
Console.ReadLine();
Console.WriteLine("方法列表-----------------------");
MethodInfo[] m=t.GetMethods();
foreach(MethodInfo i in m)
{
Console.WriteLine(i);
}
Console.ReadLine();
Console.WriteLine("事件列表-----------------------");
EventInfo[] e=t.GetEvents();
foreach(EventInfo i in e)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
using System.Reflection;
using System.Windows.Forms;class Test : Form
{
Test()
{
TextBox t = new TextBox();
t.Parent = this;
t.Multiline = true;
t.Dock = DockStyle.Fill;
t.ScrollBars = ScrollBars.Both;
Type type = t.GetType(); t.Text += "[成员列表]" + Environment.NewLine;
foreach (MemberInfo i in type.GetMembers())
{
t.Text += i.Name + Environment.NewLine;
} // 其实[成员列表]已经包含以下所有列表, 以下语句可以不要 t.Text += Environment.NewLine;
t.Text += "[属性列表]" + Environment.NewLine;
foreach (PropertyInfo i in type.GetProperties())
{
t.Text += i.Name + Environment.NewLine;
} t.Text += Environment.NewLine;
t.Text += "[方法列表]" + Environment.NewLine;
foreach (MethodInfo i in type.GetMethods())
{
t.Text += i.Name + Environment.NewLine;
} t.Text += Environment.NewLine;
t.Text += "[事件列表]" + Environment.NewLine;
foreach (EventInfo i in type.GetEvents())
{
t.Text += i.Name + Environment.NewLine;
}
} static void Main()
{
Application.Run(new Test());
}
}