DBGrid 中變換某一cell文字顏色 |
尚未結案
|
tomcheng
一般會員 發表:8 回覆:7 積分:3 註冊:2003-09-10 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
Cell[1, 1] 這格會變紅色, 可是有 bug
< class="code">
type
TCrackGrid = class(TDBGrid)
end; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
R: TRect;
begin
R := TCrackGrid(DBGrid1).CellRect(1, 1);
if (Rect.Left = R.Left) and (Rect.Top = R.Top) then begin
if (State = []) then begin
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Font.Color := clRed;
DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Column.Field.AsString);
end else begin
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Font.Color := clBlack;
DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Column.Field.AsString);
end;
end else begin
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.Font.Color := clBlack;
DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Column.Field.AsString);
end;
end; procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
gc: TGridCoord;
begin
gc := DBGrid1.MouseCoord(X, Y);
if (gc.X = 1) and (gc.Y = 1) then
DBGrid1DrawColumnCell(DBGrid1,
TCrackGrid(DBGrid1).CellRect(1, 1),
0,
DBGrid1.Columns[0],
[])
else
DBGrid1.Refresh;
end;
---
這次沒買到 cd-pro2 實在很 ... 發表人 - hagar 於 2004/03/18 17:15:19
|
tomcheng
一般會員 發表:8 回覆:7 積分:3 註冊:2003-09-10 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
type TCrackGrid = class(TDBGrid) end; // ... var Form1: TForm1; GetInRect: Boolean = False; // 判斷 mouse 是否進入第 1 欄第 1 列 implementation {$R *.DFM} procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var R: TRect; begin R := TCrackGrid(DBGrid1).CellRect(1, 1); DBGrid1.Canvas.FillRect(Rect); if GetInRect then begin if (DataCol = 0) and (R.Left = Rect.Left) and (R.Top = Rect.Top) then DBGrid1.Canvas.Font.Color := clRed else DBGrid1.Canvas.Font.Color := clBlack; end else DBGrid1.Canvas.Font.Color := clBlack; DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top, Column.Field.AsString); end; procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var gc: TGridCoord; begin gc := DBGrid1.MouseCoord(X, Y); if (gc.X = 1) and (gc.Y = 1) then begin GetInRect := True; end else GetInRect := False; DBGrid1.Refresh; end;--- 這次沒買到 cd-pro2 實在很 ... 發表人 - hagar 於 2004/03/19 14:09:00 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |