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;

posted on 2018-09-20 21:59  癫狂编程  阅读(1015)  评论(0编辑  收藏  举报

导航

好的代码像粥一样,都是用时间熬出来的