已经搞砸与此些我发现,回答我的问题
这些钱的符号是通过使用数据集字段的OnGetText事件返回格式化字符串获得的溶液:
procedure FDTableMyCurrFieldGetText(Sender: TField; var Text: string;
DisplayText: Boolean);
begin
DisplayText := True;
Text := FloatToStrF(Sender.AsCurrency, ffCurrency, 18, 2);
end;
我可以在Grid OnPainting事件中做到这一点,但这样做可以为所有链接控件以及网格设置字段格式。我使用“发件人”而不是“FDTableMyCurrField”来引用字段,以便我可以将我的数据集中所有其他货币字段的OnGetText事件指向此方法。
格式化的其余部分在网格中完成。网格的单元格没有明确暴露,但您可以像这样“TTextCell(Grid1.Columns [I] .Children [J])”)获得它们。使用网格OnPainting事件在绘制之前立即格式化单元格。
右对齐是通过设置网格中的单元格对齐来实现的。
使用样式设置单元格文字颜色。 我们需要在我们的应用程序StyleBook中创建一个“textcellnegativestyle”。这将与默认的“textcellstyle”相同,只不过“前景”刷子颜色为红色。 在桌面应用程序上,您可以在应用程序中放置TEdit,右键单击它并选择“编辑自定义样式...”,然后根据“编辑样式”命名自定义样式“textcellnegativestyle”,但只需将前景刷子颜色更改为红。
Mine是一个移动应用程序,其中“编辑自定义样式”不出现在this reason的Delphi窗体编辑器弹出菜单选项中。 要添加自定义样式,您必须使用记事本或某些文本编辑器编辑.style文件(的副本)。
- 复制/粘贴“textcellstyle”对象
- 编辑粘贴的对象的名称为“textcellnegativestyle”
- 变化的“前景”画笔颜色为红色。
- 将编辑后的文件加载到您的应用程序StyleBook中。
这里是如何看起来在我的.style文件:
object TLayout
StyleName = 'textcellnegativestyle'
DesignVisible = False
Height = 50.000000000000000000
Width = 50.000000000000000000
object TLayout
StyleName = 'content'
Align = alContents
Locked = True
Height = 42.000000000000000000
Margins.Left = 4.000000000000000000
Margins.Top = 4.000000000000000000
Margins.Right = 4.000000000000000000
Margins.Bottom = 4.000000000000000000
Width = 42.000000000000000000
end
object TBrushObject
StyleName = 'foreground'
Brush.Color = claRed
end
object TBrushObject
StyleName = 'selection'
Brush.Color = x7F72B6E6
end
object TFontObject
StyleName = 'font'
end
end
我使用Grid OnPainting事件来设置单元格对齐和风格。这里是我的工作解决方案:
procedure TFormMain.Grid1Painting(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
var
I, J: Integer;
T: TTextCell;
begin
// my Column 0 is text, all other columns are money in this example
for I := 1 to Grid1.ColumnCount - 1 do
for J := 0 to Grid1.Columns[I].ChildrenCount- 1 do
begin
T := TTextCell(Grid1.Columns[I].Children[J]);
// set the Cell text alignment to right align
T.TextAlign := TTextAlign.taTrailing;
// test the Cell string for a negative value
if (T.Text[1] = '-') then
begin
// remove the leading minus sign
T.Text := Copy(T.Text, 2, Length(T.Text) - 1);
// set the font to red using the style
T.StyleLookup := 'textcellnegativestyle';
end
else T.StyleLookup := 'textcellstyle';
end;
end;
如果它解决了,你应该留下问题作为一个问题,然后添加答案。 o.o '' – EMBarbosa