想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的改变DBGrid的颜色教程,一起来看看吧!超容易上手~
【 tulaoshi.com - 编程语言 】
//---------------------------------------------------------------------------(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)
#include vcl.h
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{
if(Column-Field-DataSet-RecNo%2)
{
DBGrid1-Canvas-Brush-Color=clSkyBlue;
DBGrid1-Canvas-FillRect(Rect);
}
DrawText(DBGrid1-Canvas-Handle, Column-Field-Text.c_str(),-1,(RECT*)&Rect,DT_SINGLELINE | DT_VCENTER |DT_CENTER);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0;iDBGrid1-Columns-Count;i++)
{ if(i%2==0)DBGrid1-Columns-Items[i]-Color=clAqua;
else DBGrid1-Columns-Items[i]-Color=clInfoBk;
}
}
//---------------------------------------------------------------------------
来源:http://www.tulaoshi.com/n/20160219/1612449.html