TStringGrid
의 셀을 클릭하면 색상이 바뀌는 앱을 만들려고합니다. 셀을 클릭 할 때마다 다음 셀로 넘어가 다음 셀을 다시 클릭 할 때까지 다음 색상으로 전환해야합니다.Delphi 7 : StringGrid에서 개별 셀의 색상을 클릭하여 변경하려면 어떻게해야합니까?
흰색 ==> 빨간색 ==> 주황색 ==> 녹색 = => 흰색 (신호 등).
내가 겪고있는 오류 (들)은 설명하기가 조금 어렵지만 시도하겠습니다.
응용 프로그램이 실행되지만 하나의 셀을 클릭 한 다음 다른 셀을 클릭하면 때로는 클릭 한 첫 번째 셀에서 색상이 변경되지만 두 번째 셀에서는 변경되지 않습니다. 다른 때에는 두 셀 모두 색상이 바뀝니다. 다른 때에는 두 셀이 모두 흰색 상태로 재설정됩니다.
type
TForm1 = class(TForm)
StringGrid: TStringGrid;
procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
arrState: array[1..4, 1..4] of Integer;
end;
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
iRow, iCol: Integer;
arrk: array[1..4, 1..4] of Integer;
begin
for iCol := 4 downto 1 do
begin
for iRow := 4 downto 1 do
begin
if (gdSelected in State) then
begin
case arrState[ARow, aCol] of
0: begin
StringGrid.Canvas.Brush.Color := clWhite;
Rect := StringGrid.CellRect(iCol, iRow);
StringGrid.Canvas.FillRect(Rect);
Inc(arrState[iRow, iCol]);
end;
1: begin
StringGrid.Canvas.Brush.Color := clRed;
Rect := StringGrid.CellRect(iCol, iRow);
StringGrid.Canvas.FillRect(Rect);
Inc(arrState[iRow, iCol]);
end;
2: begin
StringGrid.Canvas.Brush.Color := $008CFF;
Rect := StringGrid.CellRect(iCol, iRow);
StringGrid.Canvas.FillRect(Rect);
Inc(arrState[iRow, iCol]);
end;
3: begin
StringGrid.Canvas.Brush.Color := clGreen;
Rect := StringGrid.CellRect(iCol, iRow);
StringGrid.Canvas.FillRect(Rect);
arrState[iRow, iCol] := 0;
end;
end;
end;
end;
end;
end;
너무 너무 감사합니다! – Ragglepop