【发布时间】:2016-06-30 09:15:25
【问题描述】:
我想要:如果布尔变量设置为 true,StringGrid 中的单元格(错误消息)是否应该是红色的。它不能自动与 OnDrawCell 一起使用。 我怎样才能实现它?提前致谢。
【问题讨论】:
标签: delphi events binding tstringgrid
我想要:如果布尔变量设置为 true,StringGrid 中的单元格(错误消息)是否应该是红色的。它不能自动与 OnDrawCell 一起使用。 我怎样才能实现它?提前致谢。
【问题讨论】:
标签: delphi events binding tstringgrid
在OnDrawCell 事件中,检查布尔变量的状态,如果要绘制正确的单元格,则将颜色设置为红色。
见delphi : how can I change color of a cell in string grid。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if (myBooleanState) and (ACol = 3) and (ARow = 2) then
with TStringGrid(Sender) do
begin
//paint the background red
Canvas.Brush.Color := clRed;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol, ARow]);
end;
end;
当布尔值的状态发生变化时,只需调用MyStringGrid.Repaint或MyStringGrid.Invalidate即可。
【讨论】: