根据输入的值(CURRENCY类型),以不同颜色显示出来.相同的值以相同颜色. ( 积分: 1 )

  • 主题发起人 主题发起人 eire
  • 开始时间 开始时间
E

eire

Unregistered / Unconfirmed
GUEST, unregistred user!
另帖加分.
 
另帖加分.
 
我根据他人样例做过一个根据正负数改变颜色的过程,象你所有说的不同值要不同色似乎太过了?Currency是浮点数,而颜色最多只有2^32次方,何况相近的颜色根本看不出差别,因此建议你将相同级别值用相同颜色,具体实现可用查表法
 
xrs:能否发一份给我,谢谢了。
 
procedure TFrmMoney.DrawGrid4MoneyCell
(
View: TcxCustomGridTableView;
ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo;
var ADone: Boolean
);
var
value:double;
I,Len,InxSep,dig,txtLen: Integer;
fmtStr,DrawText, DrawSubText: String;
SubTextWidth,SubTextHeight: Integer;
LineLeft: Integer;
IsNegative : Boolean;
Rect,SubRect:TRect;
Prop:TcxCurrencyEditProperties;
grdCanvas:TcxCanvas;
begin
ADone:=AViewInfo.Properties is TcxCurrencyEditProperties;//不绘制非货币属性的值
if not ADone then exit;

Prop:=AViewInfo.Properties as TcxCurrencyEditProperties;
dig:=Prop.DecimalPlaces;

value:=AViewInfo.Value;
InxSep:=dig+1;
fmtStr:='0.';
for i:=1 to dig do fmtStr:=fmtStr+'0';
fmtStr := FormatFloat(fmtStr, Value);
fmtStr := StringReplace(fmtStr, '.', '', []);
IsNegative := Value<0;
if IsNegative
then fmtStr:=Copy(fmtStr,2,Length(fmtStr)-1);//去除负号

//下面循环去除前导零
txtLen:=Length(fmtStr);
if txtLen>0 then begin
I:=0;
repeat
inc(I);
until (fmtStr<>'0')or (I>txtLen);
DrawText:='';
if I=1 then DrawText:=fmtStr
else for I:=I to txtLen do
DrawText:=DrawText+fmtStr;
end else DrawText:=fmtStr;
//结束

Rect:=AViewInfo.ContentBounds;
ACanvas.Brush.Color := clWhite;
ACanvas.FillRect(Rect);
ACanvas.Font.Color := clNavy;

grdCanvas:=(View.Control as TcxGrid).Canvas;
SubTextWidth :=grdCanvas.TextWidth('佰')+4;
SubTextHeight:=grdCanvas.TextHeight('佰');
Len:=(Rect.Right-Rect.Left)div SubTextWidth;
txtLen:=Length(DrawText);
for I := 1 to Len do begin
if I > txtLen+1
then DrawSubText := ''
else if I=txtLen+1 then DrawSubText:='¥'
else DrawSubText :=Copy(DrawText, Length(DrawText) - I + 1, 1);

with ACanvas do begin
Pen.Color := GetPenColor(I,InxSep);

if IsNegative //负数则为红色
then Font.Color := clRed; //修改本句应可实现你的需求

LineLeft := Rect.Right - SubTextWidth * (I - 1);
SubRect.Left:= LineLeft - SubTextWidth + 2;
SubRect.Top:= Rect.Top + (Rect.Bottom - Rect.Top - SubTextHeight) div 2;
SubRect.Right:=LineLeft-2;
SubRect.Bottom:=Rect.Top + (Rect.Bottom - Rect.Top+SubTextHeight) div 2;
DrawTexT(DrawSubText,SubRect,cxAlignHCenter or cxAlignVCenter);
MoveTo(LineLeft, Rect.Top);
LineTo(LineLeft, Rect.Bottom);
end;
end;
end;
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
928
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部