如何使Tstringgrid中的数字都靠右,并且以货币格式显示

 StringGrid没有这样的属性设置,但利用自绘功能可以很容易地实现。如果Grid的DefaultDrawing属性设置为True(默认 值),Delphi会绘制单元格,包括背景色、边框、焦点框、固定单元格的三维效果。如果用户处理了OnDrawCell事件,Delphi会接着调用用 户的DrawCell过程。如果DefaultDrawing属性设置为False,Delphi只调用用户的DrawCell过程。我们在自行绘制单元 格时一般应设置DefaultDrawing属性为True,这样我们只需要绘制我们需要改变的单元,而其它单元交给Delphi去做好了。下面是一个简 单的例子:

 

    在这里,我们调用Win32 API的DrawText绘制字体,而DrawText可以进行左或右对齐。在绘制过程中,你可以改变文字的字体。我们没有处理背景色、边框、固定单元格 的三维效果等,因为Delphi会替我们完成的。也可以进一步添加其他效果,如货币格式。

 

 

指定单元格 只读 或是可编辑

 

procedure TfrmShowResult.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  if  (ARow =1) and ((ACol mod 10) <> 3) and ((ACol mod 10) <> 4) then
    StringGrid1.Options   :=StringGrid1.Options+[goediting]
    else
    StringGrid1.Options   :=StringGrid1.Options-[goediting] ;
end;

 

指定单元格 着色

 

procedure TfrmShowResult.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin


  if (ACol mod 10) = 3 then
  StringGrid1.Canvas.Brush.Color := $00FFE9D2
  else
  StringGrid1.Canvas.Brush.Color := clWhite;

  if (ACol mod 10) = 4 then
  StringGrid1.Canvas.Brush.Color := $00C1FFFF;

  if  (ARow =1) and ((ACol mod 10) <> 3) and ((ACol mod 10) <> 4) then
   StringGrid1.Canvas.Brush.Color :=$00E8FFD0;

  if  (ARow =0)or(ACol<3) then
  StringGrid1.Canvas.Brush.Color := clBtnFace;

end;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值