delphi7中 OnDrawColumnCell 事件怎么用
展开全部
你问的这个事件应该是dbgrid控件中的吧?这个事件是在grid控件载入数据的时候触发的,至于你这个“怎么用”波及的范围太大了,呵呵!不知道如何说起!另外还是发一段相关的代码吧,这也是我之前提过问题,别人回答的:这段代码是在数据加载时触发执行下面的代码,判断数据内容重画GRID中的单元格内容:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
const
StateText: array[0..3] of String = ('新增', '开始', '完成', '未完成');
var
x, y: Integer;
text: String;
begin
with Sender as TDBGrid do
begin
if LowerCase(Field.FieldName) = 'state' then
begin
text := StateText[Field.AsInteger];
y := (Rect.Bottom - Rect.Top - Canvas.TextHeight(text)) div 2;
x := (Rect.Right - Rect.Left - Canvas.TextWidth(text)) div 2;
Canvas.TextRect(Rect, x, y, text);
end
else
DefaultDrawDataCell(Rect, Field, State);
end;
end;
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
const
StateText: array[0..3] of String = ('新增', '开始', '完成', '未完成');
var
x, y: Integer;
text: String;
begin
with Sender as TDBGrid do
begin
if LowerCase(Field.FieldName) = 'state' then
begin
text := StateText[Field.AsInteger];
y := (Rect.Bottom - Rect.Top - Canvas.TextHeight(text)) div 2;
x := (Rect.Right - Rect.Left - Canvas.TextWidth(text)) div 2;
Canvas.TextRect(Rect, x, y, text);
end
else
DefaultDrawDataCell(Rect, Field, State);
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询