//*** DBGrid Cell 색깔 표시 ***
procedure TForm.DrawField(const Value : String;
const Rect : TRect; vCanvas : TCanvas; vFont: TFont;
vAlignment: TAlignment; FontStyle : TFontStyles; FontColor : TColor;
BGColor : TColor);
var
I : Integer;
begin
I := 0;
//First, fill in the background color of the cell
vCanvas.Brush.Color := BGColor;
vCanvas.FillRect(Rect);
//SetBkMode ensures that the background is transparent
SetBkMode(Canvas.Handle, TRANSPARENT);
//Set the passed font properties
vCanvas.Font := vFont;
vCanvas.Font.Color := FontColor;
vCanvas.Font.Style := vCanvas.Font.Style + FontStyle;
//Set Text Alignment
case vAlignment of
taRightJustify :
begin
SetTextAlign(vCanvas.Handle, TA_RIGHT);
I := Rect.Right - 2;
end;
taLeftJustify :
begin
SetTextAlign(vCanvas.Handle, TA_LEFT);
I := Rect.Left + 2;
end;
taCenter :
begin
SetTextAlign(vCanvas.Handle, TA_CENTER);
I := (Rect.Right + Rect.Left) DIV 2;
end;
end; { case }
//Draw the text
vCanvas.TextRect(Rect, I, Rect.Top + 2, Value);
SetTextAlign(vCanvas.Handle, TA_LEFT);
end;
procedure TForm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
//*** 색 표시 ***
with Sender as TDBGrid, DataSource.DataSet do
begin
if (FieldByName('강제완료체크').AsString = '진행') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clSilver);
if (FieldByName('강제완료체크').AsString = '완료') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clYellow);
if (FieldByName('강제완료체크').AsString = '강제') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clRed);
end;
end;
//*** DBGrid Cell 색깔 표시 ***
procedure TForm.DrawField(const Value : String;
const Rect : TRect; vCanvas : TCanvas; vFont: TFont;
vAlignment: TAlignment; FontStyle : TFontStyles; FontColor : TColor;
BGColor : TColor);
var
I : Integer;
begin
I := 0;
//First, fill in the background color of the cell
vCanvas.Brush.Color := BGColor;
vCanvas.FillRect(Rect);
//SetBkMode ensures that the background is transparent
SetBkMode(Canvas.Handle, TRANSPARENT);
//Set the passed font properties
vCanvas.Font := vFont;
vCanvas.Font.Color := FontColor;
vCanvas.Font.Style := vCanvas.Font.Style + FontStyle;
//Set Text Alignment
case vAlignment of
taRightJustify :
begin
SetTextAlign(vCanvas.Handle, TA_RIGHT);
I := Rect.Right - 2;
end;
taLeftJustify :
begin
SetTextAlign(vCanvas.Handle, TA_LEFT);
I := Rect.Left + 2;
end;
taCenter :
begin
SetTextAlign(vCanvas.Handle, TA_CENTER);
I := (Rect.Right + Rect.Left) DIV 2;
end;
end; { case }
//Draw the text
vCanvas.TextRect(Rect, I, Rect.Top + 2, Value);
SetTextAlign(vCanvas.Handle, TA_LEFT);
end;
procedure TForm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
//*** 색 표시 ***
with Sender as TDBGrid, DataSource.DataSet do
begin
if (FieldByName('강제완료체크').AsString = '진행') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clSilver);
if (FieldByName('강제완료체크').AsString = '완료') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clYellow);
if (FieldByName('강제완료체크').AsString = '강제') then
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [],
clBlack, clRed);
end;
end;