Reputation: 726
I have the following code (assigned to DrawGrid1.OnDrawCell event):
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
DrawGrid1.Canvas.Brush.Style:= bsFDiagonal;
DrawGrid1.Canvas.Brush.Color:= clSkyBlue;
DrawGrid1.Canvas.FillRect(Rect);
end;
It always draws black background even if the DrawGrid1.Color properties has been set to clRed. I also tried to change the Pen and Font properties, no luck. What did I miss here?
ps: I have checked this code: Diagonal brush style gives me black area. I have failed to see what is the difference between the question and the answer (apart from the commented line) and that code not working for me, as I mentioned, I already tried to change Pen properties without any result. All I want is red background with sky blue diagonal lines.
Upvotes: 3
Views: 1064
Reputation: 726
Solved, have to add SetBKColor() before FillRect:
DrawGrid1.Canvas.Brush.Style:= bsFDiagonal;
DrawGrid1.Canvas.Brush.Color:= clSkyBlue;
SetBkColor(DrawGrid1.Canvas.Handle, ColorToRGB(clRed));
DrawGrid1.Canvas.FillRect(Rect);
I still don't know why, but it's working.
Upvotes: 1