P
P
Porto_b2020-03-19 14:37:57
Delphi
Porto_b, 2020-03-19 14:37:57

Coloring StringGrrid Delphi, Color Preservation?

There is a StringGrid on the form. There is a custom function that prepares variables for use in the DrawCell event of the StringGrid object.

procedure SetColor(ARow, ACol : integer; Col : TColor);
begin
SC := True; 
AR := ARow;  //Строка (Глобальные переменные)
AC := ACol;   //Столбец
CL := Col;    //Цвет
Form1.StringGrid1.Refresh;
SC := False;
end;


The main code of the program where the decision is made to paint over the cell
...
 if step > 0 then      //Если step больше нуля, вычисляем предыдущую ячейку и закрашиваем её в желтый цвет                     
                  SetColor(cl,(cindex+((step-1) * (step-1))), clYellow); 
                   
SetColor(cl, ind, clBlue);   //Текущую ячейку закрашиваем в синий цвет  cl - строка, ind - столбец.
...


Draw event
...
  if SC then
           if (ARow = CL) and (ACol = AC) then
           Canvas.Brush.Color:=CL;

           Canvas.FillRect(Rect);
           Canvas.TextRect (Rect,Rect.Left,Rect.Top,Cells[ACol,ARow]);
           Canvas.TextRect (Rect,Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]);
...


Everything would be fine, but the previous yellow-colored cell becomes white, and the current one, as it should, is painted blue. That is, it works but the color of the previous cell is not saved and it loses its yellow color when the current cell is filled. How do you keep the color?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-03-19
@Porto_b

How do you keep the color?
Create an array of filled cells. Use OnDrawCell.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question