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

如何讓StringGrid第二欄位若大於第一欄位用紅色的字表示

答題得分者是:supman
jenlin
一般會員


發表:4
回覆:9
積分:2
註冊:2005-03-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-12 12:54:37 IP:202.39.xxx.xxx 未訂閱
我參考了站上這一段程式碼,但試不出來如何讓StringGrid第二欄位的值若大於第一欄位時,第二欄位用紅色的字表示,也就是若StringGrid1.Cells[2,1]>StringGrid1.Cells[1,1]時StringGrid1.Cells[2,1]用紅色的字表示,請幫忙提供解答,謝謝! procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin try case (StrToInt(StringGrid1.Cells[ACol, ARow]) mod 2) of 0: StringGrid1.Canvas.Font.Color := clRed; else StringGrid1.Canvas.Font.Color := clBlue; end; StringGrid1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]); except end; end;
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-12 13:11:33 IP:61.70.xxx.xxx 未訂閱
您好: 請參考以下:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
try
if (StringGrid1.Cells[ACol,ARow]>StringGrid1.Cells[ACol-1,ARow])
 then StringGrid1.Canvas.Font.Color := clRed
 else StringGrid1.Canvas.Font.Color := clBlue;
StringGrid1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]);
except
end;
end;    procedure TForm1.FormActivate(Sender: TObject);
begin
StringGrid1.Cells[4,1]:='30';//紅
StringGrid1.Cells[3,1]:='10';//籃
StringGrid1.Cells[2,1]:='20';//紅
StringGrid1.Cells[1,1]:='10';//紅
end;
發表人 - supman 於 2005/04/12 13:17:32
jenlin
一般會員


發表:4
回覆:9
積分:2
註冊:2005-03-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-04-12 13:27:33 IP:202.39.xxx.xxx 未訂閱
對不起,我沒說清楚,我共有九個欄位,只要處理第二欄位>第一欄位時,第二欄位用紅字表示,其餘欄位都是用黑色字表示,謝謝!
supman
尊榮會員


發表:29
回覆:770
積分:924
註冊:2002-04-22

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-04-12 13:50:14 IP:61.70.xxx.xxx 未訂閱
您好: 參考如下:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
try
if (ACol=1) or (ACol=2) then
 begin
  if (StringGrid1.Cells[ACol,ARow]>StringGrid1.Cells[ACol-1,ARow])
   then StringGrid1.Canvas.Font.Color := clRed
   else StringGrid1.Canvas.Font.Color := clBlue;
 end
 else StringGrid1.Canvas.Font.Color := clBlack;
StringGrid1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]);
except
end;
end;
jenlin
一般會員


發表:4
回覆:9
積分:2
註冊:2005-03-30

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-04-12 14:44:16 IP:202.39.xxx.xxx 未訂閱
感謝您提供解答,您的解答已經解決了這個問題,謝謝!
系統時間:2024-07-07 12:59:19
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!