用RXLIB组件包的TCurrencyEdit。我这里有

解决方案 »

  1.   

    用一个string存放字符,然后截取位数显示在label里,我原来用vb做的一个计算器就是怎么做的。至于显示效果则是把label放到panel里。
      

  2.   

    看看下面的代码,对你也许有启发!
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    var
      i:word;
      old:tfont;
    begin
      old:=canvas.Font;
      canvas.Font:=edit1.Font;
      i:=sendmessage(edit1.handle,EM_GETMARGINS,0,0);
      wordrec(i).lo:=wordrec(i).lo-canvas.TextWidth(key);
      sendmessage(edit1.Handle,EM_SETMARGINS,EC_LEFTMARGIN,i);
      canvas.Font:=old;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      i:word;
    begin
      wordrec(i).lo:=60;
      wordrec(i).hi:=0;
      sendmessage(edit1.Handle,EM_SETMARGINS,EC_LEFTMARGIN,i);
    end;
      

  3.   

    继承一个控件,在createparams中设为ES_RIGHT
      

  4.   

    从右向左显示的小控件功能比TEDIT简化了一些(主要是一些不重要的属性一般不影响使用)
    已测试 ok 
    如果有问题请联系 [email protected] CustomEdit_R;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TCustomEdit_R = class(TCustomEdit)
      protected
        procedure CreateParams(var Params: TCreateParams);override;
      published
        property Anchors;
        property AutoSelect;
        property AutoSize;
        property BiDiMode;
        property BorderStyle;
        property CharCase;
        property Color;
        property Constraints;
        property Ctl3D;
        property DragCursor;
        property DragKind;
        property DragMode;
        property Enabled;
        property Font;
        property HideSelection;
        property ImeMode;
        property ImeName;
        property MaxLength;
        property OEMConvert;
        property ParentBiDiMode;
        property ParentColor;
        property ParentCtl3D;
        property ParentFont;
        property ParentShowHint;
        property PasswordChar;
        property PopupMenu;
        property ReadOnly;
        property ShowHint;
        property TabOrder;
        property TabStop;
        property Text;
        property Visible;
        property OnChange;
        property OnClick;
        property OnContextPopup;
        property OnDblClick;
        property OnDragDrop;
        property OnDragOver;
        property OnEndDock;
        property OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnStartDock;
        property OnStartDrag;
      end;
    procedure Register;implementation
    const
      BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);procedure TCustomEdit_R.CreateParams(var Params: TCreateParams);
     const
     Passwords: array[Boolean] of DWORD = (0, ES_PASSWORD);
      ReadOnlys: array[Boolean] of DWORD = (0, ES_READONLY);
      CharCases: array[TEditCharCase] of DWORD = (0, ES_UPPERCASE, ES_LOWERCASE);
      HideSelections: array[Boolean] of DWORD = (ES_NOHIDESEL, 0);
      OEMConverts: array[Boolean] of DWORD = (0, ES_OEMCONVERT);
    begin
      inherited CreateParams(Params);
      CreateSubClass(Params, 'EDIT');
      with Params do
      begin
        Style := Style or (ES_AUTOHSCROLL or ES_AUTOVSCROLL or ES_RIGHT );// or
       {   BorderStyles[FBorderStyle] or Passwords[FPasswordChar <> #0] or
          ReadOnlys[FReadOnly] or CharCases[FCharCase] or
          HideSelections[FHideSelection] or OEMConverts[FOEMConvert];
        if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
        begin
        }
          Style := Style and not WS_BORDER;
          ExStyle := ExStyle or WS_EX_CLIENTEDGE;
      //  end;
      end;
    end;procedure Register;
    begin
      RegisterComponents('Samples', [TCustomEdit_R]);
    end;end.
      

  5.   

    我编写计算器程序时本来也先用的是 TEdit,来当显示屏,但是发现不能从右向左的显示,于是我改用的TLabel来做显示屏。所以,我觉得你们的讨论很有价值~
      

  6.   

     从右向左显示的小控件 已test okunit Edit_Ex;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TEdit_Ex = class(TEdit)
      private
        FTextOnRight:Boolean;
        function  GetTextOnRight:Boolean;
        procedure SetTextOnRight(Value:Boolean);
      protected
        procedure CreateParams(var Params: TCreateParams);override;
      published
        property TextOnRight:Boolean read FTextOnRight write FTextOnRight default False;// write SetSelText;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TEdit_Ex]);
    end;function TEdit_Ex.GetTextOnRight:Boolean;
      begin
       Result:=Self.FTextOnRight;
      end;procedure TEdit_Ex.SetTextOnRight(Value:Boolean);
     begin
      if Self.FTextOnRight<>Value then Self.FTextOnRight:=Value;
     end;procedure TEdit_Ex.CreateParams(var Params: TCreateParams);
     begin
      inherited;
      if self.FTextOnRight then Params.Style:=Params.Style or ES_RIGHT;
     end;end.
      

  7.   

    (更正 精简代码)
    从右向左显示的小控件 已test ok
    unit Edit_Ex;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TEdit_Ex = class(TEdit)
      private
        FTextOnRight:Boolean;
      protected
        procedure CreateParams(var Params: TCreateParams);override;
      published
        property TextOnRight:Boolean read FTextOnRight write FTextOnRight default False;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TEdit_Ex]);
    end;procedure TEdit_Ex.CreateParams(var Params: TCreateParams);
     begin
      inherited;
      if self.FTextOnRight then Params.Style:=Params.Style or ES_RIGHT;
     end;end.
      

  8.   

    lwm 兄,还有各位大侠,多谢你们的指点,现在我已经解决了此问题。
       请你们原谅我把分全给了LWM,因为,我觉得他敲这多么源码,这30分还不足以报答。
    但我还是要多多感谢大家帮助我,以后,我会多多送分的!谢谢!