通过实现对MS控件的继承并重写事件,能让你在做项目中速度大加提高.我现在做的井下定位系统很多控件都是经自已重写过.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Costaco.CTN.Controls
......{
public class DataGridView : System.Windows.Forms.DataGridView
......{
public DataGridView()
......{
}
//这里键入override,然后空格就会出来重写的列表,你选一个回车就可以了写出不同的override
protected override void OnDataBindingComplete(DataGridViewBindingCompleteEventArgs e)
......{
if (this.Rows.Count != 0)
......{
for (int i = 0; i < this.Rows.Count; i++)
......{
if ((i % 2) == 1)
......{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.WhiteSmoke;
}
else
......{
this.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
}
}
} 
base.OnDataBindingComplete(e);
}

}
}


通过继承原有的控件,直接实现交替颜色,也可以实现多行交替颜色。

本文介绍了一种通过继承和重写.NET Framework中的DataGridView控件的方法,以实现自定义功能,如自动设置表格行的背景颜色为交替颜色。这种方式能够简化开发流程并提高效率。
1765

被折叠的 条评论
为什么被折叠?



