線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1709
推到 Plurk!
推到 Facebook!

How to call ONDRAWDATACELL in ButtonClick

尚未結案
ken.hsueh
一般會員


發表:1
回覆:0
積分:0
註冊:2008-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-15 16:38:38 IP:60.212.xxx.xxx 訂閱
When I Click a Button, and I want to chang a record's font color in DBGRID that i selected,I try to call ONDRAWDATACELL , the statement as following :

DBGrid1.Canvas.Font := clRed;
DBgrid1.OnDrawDataCell(DBGrid1,Rect,Field,State);

But I get a compiler error message :

[Error] srcUser0120.pas(343): There is no overloaded version of 'Rect' that can be called with these arguments

How can I call OnDrawDataCell when I click a Button?
christie
資深會員


發表:30
回覆:299
積分:475
註冊:2005-03-25

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-04-15 17:19:26 IP:203.73.xxx.xxx 未訂閱
根據Help文件
Do not write an OnDrawDataCell event handler. OnDrawDataCell is obsolete and included for backward compatibility. Instead, write an OnDrawColumnCell event handler.
的說法,請少用OnDrawDataCell。

您可改用OnDrawColumnCell,舉例如下
procedure TFORM1.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 TFORM1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
inherited;
with Sender as TDBGrid, DataSource.DataSet do
begin
if QtabR_AM.AsInteger =0 then // 紫
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsBold],
clPurple,$00D2D2FF)
else
if Qtab_t65.AsFloat >1.3 then // 紅字
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsBold],
clRed, $00D2D2FF)
else
if Qtab_t65.AsFloat <0.7 then //橄欖 綠
DrawField(Column.Field.DisplayText, Rect, Canvas,
Column.Font, Column.Alignment, [fsBold],
clOlive,$00D2D2FF)
end;
end;

===================引 用 ken.hsueh 文 章===================
When I Click a Button, and I want to chang a record's font color in DBGRID that i selected,I try to call ONDRAWDATACELL , the statement as following :

DBGrid1.Canvas.Font := clRed;
DBgrid1.OnDrawDataCell(DBGrid1,Rect,Field,State);

But I get a compiler error message :

[Error] srcUser0120.pas(343): There is no overloaded version of 'Rect' that can be called with these arguments

How can I call OnDrawDataCell when I click a Button?
------
What do we live for if not to make life less difficult for each other?
系統時間:2024-11-22 13:41:17
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!