TStringGrid 繪製問題 |
尚未結案
|
tidal
初階會員 ![]() ![]() 發表:93 回覆:32 積分:25 註冊:2003-07-15 發送簡訊給我 |
|
Chance36
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
試試這樣如何?? unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure FormShow(Sender: TObject); procedure StringGrid1DblClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var Obj : TstringGrid; Begin Obj := TStringgrid(Sender); // 要變換顏色的判斷 If Integer(TStringGrid(Sender).Objects[ACol,ARow]) = 1 Then Begin Obj.Canvas.Brush.Color := clRed; If gdSelected IN State Then Obj.Canvas.Brush.Color := clRed; If gdFocused IN State Then Obj.Canvas.Brush.Color := clRed; End; Obj.Canvas.FillRect(Rect); Obj.Canvas.TextOut(Rect.Left 2,Rect.Top 2,Obj.Cells[ACol,ARow]); End; procedure TForm1.FormShow(Sender: TObject); begin StringGrid1.Rows[0].CommaText := 'C00,C01,C02,C03,C04' ; StringGrid1.Rows[1].CommaText := 'C10,C11,C12,C13,C14' ; StringGrid1.Rows[2].CommaText := 'C20,C21,C22,C23,C24' ; StringGrid1.Rows[3].CommaText := 'C30,C31,C32,C33,C34' ; StringGrid1.Rows[4].CommaText := 'C40,C41,C42,C43,C44' ; end; procedure TForm1.StringGrid1DblClick(Sender: TObject); begin With StringGrid1 Do Begin If Integer(Objects[Col,Row]) = 1 Then Begin // 要換顏色 Objects[Col,Row] := TObject(0); End Else Begin Objects[Col,Row] :=TObject(1); End; End; end; end._______________________________________ 深藍的魚,祝您好運..........連連 |
tidal
初階會員 ![]() ![]() 發表:93 回覆:32 積分:25 註冊:2003-07-15 發送簡訊給我 |
|
Chance36
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
引言: 還有, 怎樣寫一個for loop 去check 所有cells, 看那個cells 轉了顏色. 再把那個cell的row 和 col 紀錄在一個array 上?解說的部份,我已加上去了 Var ArLog : Array Of Array[0..1] Of Integer ; i, j, c : Integer ; Begin c := 0 ; With StringGrid Do Begin For i:= FixedRows To RowCount - 1 Do Begin // 逐列掃描 For j:= FixedCols To ColCount - 1 Do Begin // 逐行掃描 If Integer(Objects[j,i]) = 1 Then Begin // SetLength(ArLog,c 1); // 將陣列元素加大 Arlog[c][0] := j ; // 儲存[行] Arlog[c][1] := i ; // 儲存[列] Inc(c); End; End; End; End; End;_______________________________________ 深藍的魚,祝您好運..........連連 |
tidal
初階會員 ![]() ![]() 發表:93 回覆:32 積分:25 註冊:2003-07-15 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |