TDBGrid의 OnDrawColumnCell 이벤트에서 다음과 같이 코드를 붙이면 됩니다.
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.Index = 1 then
with DBGrid1.Canvas do
begin
Brush.Color := clBlue;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, Column.Field.Value);
end;
end;
이승근 님이 쓰신 글 :
: procedure Twonjang6F.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;
: vCanvas.FillRect(Rect);
: SetBkMode(Canvas.Handle, TRANSPARENT);
: vCanvas.Font := vFont;
: vCanvas.Font.Style := FontStyle;
: vCanvas.Font.Color := FontColor;
: vCanvas.brush.Color := BGColor;
: 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;
: vCanvas.TextRect(Rect, I, Rect.Top + 2, Value);
: SetTextAlign(vCanvas.Handle, TA_LEFT);
: end;
:
: procedure Twonjang6F.DBGrid1DrawColumnCell(Sender: TObject;
: const Rect: TRect; DataCol: Integer; Column: TColumn;
: State: TGridDrawState);
: begin
: with Sender as TDBGrid, DataSource.DataSet do
: if FieldByName('gub1').AsString = '@' then
: DrawField(Column.Field.DisplayText, Rect, Canvas, Column.Font, Column.Alignment, [], clBlue, clWindow);
: end;
:
: 보통 위의 형식으로 행의 색은 바꾸었는데 특정열 즉, 특정 필드의 글자들만 색상을 바꾸고 싶습니다...
: 예를 들어 a1, a2, a3, a4... 등의 필드가 있고 이것이 모두 DBGrid에 표시가 된다면 이중 a2필드의 글자들만 window바탕에 파란색으로 표시하고 싶습니다... 나머지는 물론 자연 그대로 표시하구요...
: 어떻게 할까요??
|