代码:
private void gvSendConfirm_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
string sCurrTime=DbHelperSql.GetSingle("Select GetDate() DateNow").ToString();
DateTime dtCurrTime,dtSendTime;
int iMinutes = 0;
try
{
dtCurrTime=DateTime.Parse(sCurrTime);
}
catch (System.Exception ex)
{
dtCurrTime=DateTime.Now;
}
string sSendTime= gvSendConfirm.GetDataRow(e.RowHandle)["UpdateTime"].ToString();
try
{
dtSendTime = DateTime.Parse(sSendTime);
}
catch (System.Exception ex)
{
dtSendTime = DateTime.Now;
}
//计算时间差。
System.TimeSpan difTime = dtCurrTime.Subtract(dtSendTime);
iMinutes = difTime.Minutes;
if (iMinutes <= iTimeOutLevel1)
{
e.Appearance.BackColor = Color.White; //设置背景色
}
else if (iMinutes > iTimeOutLevel1 && iMinutes <= iTimeOutLevel2)
{
e.Appearance.BackColor = Color.FromArgb(192, 192, 255);//设置背景色
}
else if (iMinutes > iTimeOutLevel2 && iMinutes <= iTimeOutLevel3)
{
e.Appearance.BackColor = Color.FromArgb(128, 255, 128);//设置背景色
}
else if (iMinutes > iTimeOutLevel3 && iMinutes <= iTimeOutLevel4)
{
e.Appearance.BackColor = Color.FromArgb(255, 192, 128);//设置背景色
}
else if (iMinutes > iTimeOutLevel4 && iMinutes <= iTimeOutLevel5)
{
e.Appearance.BackColor = Color.FromArgb(255, 128, 128);//设置背景色
}
else if (iMinutes > iTimeOutLevel5 && iMinutes <= iTimeOutLevel6)
{
e.Appearance.BackColor = Color.Red;//设置背景色
}
else if (iMinutes > iTimeOutLevel6)
{
e.Appearance.BackColor = Color.Crimson;//设置背景色
}
e.Appearance.ForeColor = Color.Black; //设置字体颜色
}
原文地址:https://www.cnblogs.com/kliine/p/9246736.html