批量给控件赋值
方法一:利用Controls.Find方法方法二:利用反射(该方法可批量给控件任何属性赋值)[@more@]方法一:利用Controls.Find方法:for(int i = 0 , i < 10 , i++){ Label newLabel = (System.Windows.Forms.Label)this.Controls.Find("label1" + i.toString(),false)[0]; newLabel .Text = i.toString(); } 方法二:利用反射(该方法可批量给控件任何属性赋值)for(int i = 0 , i < 10 , i++){//取类型System.Type type = typeof(System.Windows.Forms.Label);//取属性名称System.Reflection.PropertyInfo p = type.Ge
C# interface以及工厂模式
C# interface定义:就是以前使用的类似于API 的东西,别人告诉你一个类型,你在心得开发过程中可以使用。[@more@]C# interface定义:就是以前使用的类似于API 的东西,别人告诉你一个类型,你在心得开发过程中可以使用。比如:interface ITest { string iText(); } class Test:ITest { #region ITest Members public string iText() { // TODO:Add Test.printText implementation return ("Test string."); } #endregion } class Test2:ITest { #region ITest
ListView 可编辑
ListView本不可以直接编辑,一般是使用模拟一个输入对象,来进行编辑,然后再保存回去。下面就是介绍了这个方法 用的不是C# 但思路可以借鉴[@more@]unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) ListView1: TListView; Edit1: TEdit; Button1: TButton; procedure Button1Clic
DataGridView的数据绑定 与 指定列显示 (代码完成)
在Winform中使用DataGridView,将从数据库读出来的数据进行数据绑定,并做到对指定列的绑定,为空附空值等操作...[@more@]Element element = new Element(); IList<ElementInfo> elementInfos = element.GetElementInfo(); dgvSlagMaterialAnalysis.DataSource = elementInfos; DataGridViewTextBoxColumn ElementName = new DataGridViewTextBoxColumn(); ElementName.DataPropertyName = "ElementShortName"; ElementName.HeaderText = "元素名称";