捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:为DBGrid绘制中文帐簿金额栏改进版
dcy 23271 2006/4/27 23:52:41
楼上多虑
mengstart 21908 2006/3/5 2:46:05
呵呵,楼上的代码前面最好加一行
if AViewInfo.Item.Name<>'je' then Exit;  // 'je'为要需用金额栏显示的列名
限制一下,否则每行都变成金额栏了
dajun 17816 2005/9/14 8:49:38
//CXGrid在OnCustomDrawCell里处理显示
procedure TMainForm.cxGrid1DBTableView1WageCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
    S,ATextToDraw: String;
    i, x, y, iTextWidth: Integer;
    Rect: TRect;
begin
    ATextToDraw := AViewInfo.GridRecord.DisplayTexts[AViewInfo.Item.Index];
    Rect:=AViewInfo.Bounds;
    with ACanvas.Canvas do
    begin
        iTextWidth := TextWidth('8') + 4;
        y := Rect.Top + (Rect.Bottom - Rect.Top - TextHeight('8')) div 2;
        S := StringReplace(FormatFloat('0.00', AViewInfo.Value), '.', ', []);
        if AViewInfo.Value < 0 then Font.Color := clRed;

        FillRect(Rect);

        i := (Rect.Right - Rect.Left) div iTextWidth;
        repeat
          x := Rect.Right - iTextWidth * i;
          if i <= Length(S) then
          TextOut(x+3, y, S[Length(S)-i+1]);

          if i = 2 then
          Pen.Color := clRed
          else if (i = 0) or ( (i>2) and (((i-2) mod 3) = 0) ) then
          Pen.Color := clGreen
          else
          Pen.Color := clSilver;
          MoveTo(x, Rect.Top);
          LineTo(x, Rect.Bottom);
          Dec(i);
        until (i<0);
        ACanvas.FrameRect(Rect);
        ADone:=True;
    end;
end;
conch 17692 2005/9/9 17:12:28
广东人。

我没用TwwDBLookupComb。如果它继承自TCustomCombo,能通过cbbXXX.DroppedDown读取/设置下拉属性;否则你可以尝试向控件发送CB_GETDROPPEDSTATE,看是否返回正确信息。都不行的话,可以用FindWindow查找下拉列表的类名(下拉列表是一独立的窗体),以判断是否在下拉状态。
dgy_snakeking 17641 2005/9/7 16:13:27
顺便问下conch,Delphi里怎判断TwwDBLookupComb是否已经是下拉状态?,以前用VB时,自己写一个 WindowProc,截获 CBN_DROPDOWN 和 CBN_CLOSEUP 消息设置一个变量,收到 CBN_DROPDOWN 时 + 1,收到 CBN_CLOSEUP 时 - 1,Delphi里有没有直接点的方法?
dgy_snakeking 17640 2005/9/7 16:06:46
conch老大是湖南四川人???
qiuzhidong 17636 2005/9/7 10:49:37
conch大老:
  只要那表格标题是自己加进去设置的,就看不到效果了。不信你试试
conch 17621 2005/9/7 8:13:49
原来是这个意思,并不是金额栏单元格的问题,早响嘛。
改用DrawText绘文字,无论你想要文字缩略(DT_END_ELLIPSIS)还是断行(DT_WORDBREAK、去掉DT_SINGLELINE)都很容易。
如果懒得写的话可以用DBGridEh,设置属性即可。
dgy_snakeking 17605 2005/9/6 16:37:24
conch大老:
(间隔色不且反差大太,而且应尽量避开gdSelected的单元格,把以下代码加到if Field.DataType <> ftBCD then Exit;前面:

----------
不是前面的被后面的擦掉了,就是后面的被前面的擦掉了,难看,不能实现象速达3000里那样,网格线换行+金额栏的完美行态.老大,救命啊
brighteye 17598 2005/9/6 13:46:43
to conch:
  我不是指金额栏换行。比如一张财务记帐凭证,基本栏目有摘要,科目,借方金额,贷方金额。摘要栏有可能文字较多,一行显不下,所以就是希望摘要栏能够设置换行
conch 17583 2005/9/6 8:10:28
to brighteye:
我从未见到有换行的金额栏
conch 17582 2005/9/6 8:07:49
间隔色不且反差大太,而且应尽量避开gdSelected的单元格,把以下代码加到if Field.DataType <> ftBCD then Exit;前面:

    with TDBGrid(Sender) do begin
        if (not (gdSelected in State)) and ((DataSource.DataSet.RecNo mod 2) = 1) then 
          Canvas.Brush.Color := $EEEEEE;
        DefaultDrawDataCell(Rect, Field, State);
    end;
dgy_snakeking 17579 2005/9/5 23:05:15
conch老大,我想即支持金额栏,又隔行换颜色.呵呵,最后发现有点难看,不知老大可否给个例子
iwan2play 17492 2005/9/2 11:03:40
还是没办法。算了。
iwan2play 17491 2005/9/2 11:02:58
好像这个两个单引号不能同时使用,改了也不行的。呵呵应该这样“
S := '¥'+trim(StringReplace(FormatFloat('0.00', Field.AsCurrency), '.', ', [])); ”
网页怎么自动修改了内容,呵呵。
iwan2play 17489 2005/9/2 10:59:11
老大,不错就是掉了一个引号,提醒其他跟我粗心的人。
S := '¥'+trim(StringReplace(FormatFloat('0.00', Field.AsCurrency), '.', ', []))
应该
S := '¥'+trim(StringReplace(FormatFloat('0.00', Field.AsCurrency), '.', ', []))
yx770209 17440 2005/9/1 14:48:31
改进了一下加入了“¥”
procedure TMainForm.DestGridDrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
var
    S: String;
    i, x, y, iTextWidth,h: Integer;
begin
    if Field.DataType <> ftBCD then Exit;

    with TDBGrid(Sender).Canvas do begin
        h:=1;
        iTextWidth := TextWidth('8') + 4;
        y := Rect.Top + (Rect.Bottom - Rect.Top - TextHeight('8')) div 2;
        S := '¥'+trim(StringReplace(FormatFloat('0.00', Field.AsCurrency), '.', ', []));
        if Field.AsCurrency < 0 then Font.Color := clRed;

        FillRect(Rect);

        i := (Rect.Right - Rect.Left) div iTextWidth;
        repeat
          x := Rect.Right - iTextWidth * i;
          if i <= Length(S) then
          if S[Length(S)-i+1] in ['0'..'9','-'] then
          TextOut(x+3, y, S[Length(S)-i+1])
          else
          if h=1 then
          begin
           TextOut(x+10, y, '¥');
          h:=2;
          end;

          if i = 2 then
          Pen.Color := clRed
          else if (i = 0) or ( (i>2) and (((i-2) mod 3) = 0) ) then
          Pen.Color := clGreen
          else
          Pen.Color := clSilver;
          MoveTo(x, Rect.Top);
          LineTo(x, Rect.Bottom);
          Dec(i);
        until (i<0);
    end;
end;
brighteye 17372 2005/8/31 9:59:03
老大,能加上满格显示吗?还有能加上换行显示(wrap)就更巴适了,我用Ehlib好象中文可以换行,英文不能换行呢
conch 17362 2005/8/31 8:28:22
老大倒不敢当,你也没必要这样说,能出书也得人家愿意翻来看,如果人家连书都懒得翻,你出什么也没用。
czchawk 17292 2005/8/29 12:17:05
佩服佩服,老大你可以出书了。
第一页 上一页 下一页 最后页 有 28 条纪录 共2页 1 - 20
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表