Delphi 在单元格中输入数据时更改StringGrid的单元格颜色。德尔菲
晚上好,我想知道在单元格中写入数据时如何更改单元格的颜色 我有这个Delphi 在单元格中输入数据时更改StringGrid的单元格颜色。德尔菲,delphi,Delphi,晚上好,我想知道在单元格中写入数据时如何更改单元格的颜色 我有这个 procedure TFrmReportes.SGDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if (gdSelected in State) then begin SG.Canvas.Brush.Color := rgb(255,119,119);
procedure TFrmReportes.SGDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if (gdSelected in State) then
begin
SG.Canvas.Brush.Color := rgb(255,119,119);
SG.Canvas.FillRect(SG.CellRect(ACol, ARow));
SG.Canvas.TextOut(Rect.Left+2,Rect.Top+2, SG.Cells[ACol, ARow]);
end;
end;
但当在单元格中输入数据时,它会变为白色
再次感谢 TStringGrid在当前正在编辑的单元格顶部显示一个。该编辑覆盖整个单元格。这就是为什么看不到自定义图形的原因。您需要更改TInplaceEdit的颜色属性。您可以通过属性访问TInplaceEdit
我建议从TStringGrid派生一个新组件,并重写其虚拟方法。如果表单中只有一个网格,则一个简单的插入器就足够了,例如:
类型
TStringGrid=classVcl.Grids.TStringGrid
受保护的
函数CreateEditor:TInplaceEdit;推翻
终止
TFrmReportes=classTForm
SG:TStringGrid;
...
终止
...
类型
TInplaceEditAccess=classTInplaceEdit
终止
函数TStringGrid.CreateEditor:TInplaceEdit;
开始
结果:=继承的CreateEditor;
TInplaceEditAccessResult.Color:=RGB255、119、119;
终止
TStringGrid在当前正在编辑的单元格顶部显示一个。该编辑覆盖整个单元格。这就是为什么看不到自定义图形的原因。您需要更改TInplaceEdit的颜色属性。您可以通过属性访问TInplaceEdit
我建议从TStringGrid派生一个新组件,并重写其虚拟方法。如果表单中只有一个网格,则一个简单的插入器就足够了,例如:
类型
TStringGrid=classVcl.Grids.TStringGrid
受保护的
函数CreateEditor:TInplaceEdit;推翻
终止
TFrmReportes=classTForm
SG:TStringGrid;
...
终止
...
类型
TInplaceEditAccess=classTInplaceEdit
终止
函数TStringGrid.CreateEditor:TInplaceEdit;
开始
结果:=继承的CreateEditor;
TInplaceEditAccessResult.Color:=RGB255、119、119;
终止
由于您在上一个示例中的建议,我找到了以下代码 使用InplaceEditor属性
type
THackGrid = class(TCustomGrid)
public
property InPlaceEditor;
property EditorMode;
end;
TFrmReportes = class(TForm)
SG: TStringGrid;
...
end;
...
procedure TFrmReportes.Button1Click(Sender: TObject);
begin
THackGrid(SG).InPlaceEditor.Brush.Color := RGB(255, 119, 119);
end;
非常感谢由于您在上一个示例中的建议,我找到了以下代码 使用InplaceEditor属性
type
THackGrid = class(TCustomGrid)
public
property InPlaceEditor;
property EditorMode;
end;
TFrmReportes = class(TForm)
SG: TStringGrid;
...
end;
...
procedure TFrmReportes.Button1Click(Sender: TObject);
begin
THackGrid(SG).InPlaceEditor.Brush.Color := RGB(255, 119, 119);
end;
多谢各位