可以直接通过反射获取当前窗体的所有控件的Text(具有Text属性),具体代码如下:

foreach (var field in form.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public))
{
string fieldValue = "";
try
{
PropertyInfo proText = field.FieldType.GetProperty("Text");
if (field.FieldType == typeof(System.Windows.Forms.Label) ||
field.FieldType == typeof(DevComponents.DotNetBar.LabelX)
)
{
fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(System.Windows.Forms.Button) ||
field.FieldType == typeof(DevComponents.DotNetBar.ButtonX) ||
field.FieldType == typeof(GPOS.Controls.ButtonNew)
)
{
fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(DevComponents.DotNetBar.ButtonItem) ||
//field.FieldType == typeof(DevComponents.DotNetBar.TextBoxItem) ||
field.FieldType == typeof(DevComponents.DotNetBar.LabelItem)
)
{
fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(System.Windows.Forms.ToolStripMenuItem)
)
{
fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(System.Windows.Forms.ToolStripButton)
)
{
// fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
PropertyInfo proToolTipText = field.FieldType.GetProperty("ToolTipText");
fieldValue = proToolTipText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(System.Windows.Forms.CheckBox) ||
field.FieldType == typeof(DevComponents.DotNetBar.Controls.CheckBoxX)
)
{
fieldValue = proText.GetValue(field.GetValue(form), null).ToString();
}
else if (field.FieldType == typeof(System.Windows.Forms.DataGridViewTextBoxColumn) ||
field.FieldType == typeof(System.Windows.Forms.DataGridViewCheckBoxColumn)
)
{
PropertyInfo proHeaderText = field.FieldType.GetProperty("HeaderText");
fieldValue = proHeaderText.GetValue(field.GetValue(form), null).ToString();
}
else
{
continue;
}
}
catch
{ }
}

代码

最新文章

  1. [No000087]Linq排序,SortedList排序,二分法排序性能比较
  2. 判断是否IPv6网络
  3. 【转】Python资源 转自 dylanninin.com
  4. VB 笔记
  5. Dependency Injection in ASP.NET Core
  6. D. Green and Black Tea
  7. flex 简单跑马灯效果(竖着显示)
  8. python基础===zip在python3中的用法
  9. MAC下用homebrew安装及配置apache、php和mysql
  10. js 数据加载loading封装
  11. STM32学习笔记
  12. [C]gcc编译器的一些常用语法
  13. ASP.NET Web API实现微信公众平台开发(二)access_token与定时任务
  14. apache httpd.conf
  15. 微信小程序制作家庭记账本之六
  16. JavaScript Math和Number对象研究
  17. python3爬虫-爬取新浪新闻首页所有新闻标题
  18. SqlServer收缩日志文件
  19. Selenium2+python自动化51-unittest简介
  20. 2016"百度之星" - 初赛(Astar Round2B)1003 瞬间移动 组合数学+逆元

热门文章

  1. svn服务的安装和使用
  2. 【题解】 CF11D A Simple Task
  3. C语言实现 操作系统 银行家算法
  4. IO多路复用之Reactor模式
  5. TensorFlow Action(开山使用篇)
  6. node+express上传图片到七牛
  7. 在Linux下创建7种类型的文件
  8. 在高通平台Android环境下编译内核模块【转】
  9. 笔记 jsp/ajax/js/jquery/html5/css+div->table
  10. PHP闭包详解