Reputation: 666
Is there any way to paint specific cells on Delphi's TStringGrid without using the OnDrawCell event, for instance if I click a button the specified cells will be painted depending on their content.
Upvotes: 2
Views: 2335
Reputation: 16612
No, that is not possible. The next time Windows decides to redraw the control (something you can't really control), everything you have drawn will be overpainted by the Control's Paint
method and all painting-related events.
You have to use the event approach to do custom painting like that as Jeroen points out.
Upvotes: 3
Reputation: 24463
To keep the painting persistent, the way you should do this is as follows:
--jeroen
Upvotes: 11
Reputation: 9294
procedure TForm1.Button1Click(Sender: TObject);
var aRect: TRect;
begin
aRect := StringGrid1.CellRect(2,2);
StringGrid1.Canvas.Brush.Color := clBlue;
StringGrid1.Canvas.FillRect(aRect);
StringGrid1.Canvas.Font.Color := clBlack;
StringGrid1.Canvas.TextOut(aRect.Left + 2 , aRect.Top + 2, StringGrid1.Cells[2, 2]);
end;
Upvotes: 1