解决方案 »

  1.   

    不带DB的可能没有!
    可能考虑用第三方控件,如:rx
      

  2.   

    Express Editors控件可以实现,你想实现看看源码也许有用
      

  3.   

    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=7946
      

  4.   

    那个FAQ里面说的很清楚了吧,就是重新覆盖edit的createparam过程,使其拥有Center的样式
      

  5.   

    unit QFltEdit;interfaceuses
      Windows, Messages, SysUtils, Classes,StdCtrls,Controls,Forms;type
      TFloatEdit = class(TCustomEdit)
      private
        { Private declarations }
        FPrecision:Integer;
        FTextAlign:TAlignment;
        //procedure SetPrecision(value:Integer);
        procedure SetTextAlign(value:TAlignment);
        procedure WMChar(var Message: TWMChar); message WM_CHAR;
      protected
        { Protected declarations }
        function DoKeyPress(var Message: TWMKey): Boolean;
      public
        { Public declarations }
        constructor Create(AOwner:TComponent);override;
        procedure CreateParams(var Params: TCreateParams); override;
        function TextAsInteger:Integer;
        function TextAsFloat:Extended;
      published
        { Published declarations }
        property Precision:Integer read FPrecision write FPrecision default 2;
        property TextAlign:TAlignment read FTextAlign write SetTextAlign ;
        property Anchors;
        property AutoSelect;
        property AutoSize;
        property BorderStyle;
        property CharCase;
        property Color;
        property Constraints;
        property DragMode;
        property Enabled;
        property Font;
        property HideSelection;
        property MaxLength;
        property ParentColor;
        property ParentFont;
        property ParentShowHint;
        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 OnEndDrag;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;
        property OnStartDrag;
      end;implementation
    uses Tools;
    {
    VK_NUMPAD0 0 key (numeric keypad)
    VK_NUMPAD1 1 key (numeric keypad)
    VK_NUMPAD2 2 key (numeric keypad)
    VK_NUMPAD3 3 key (numeric keypad)
    VK_NUMPAD4 4 key (numeric keypad)
    VK_NUMPAD5 5 key (numeric keypad)
    VK_NUMPAD6 6 key (numeric keypad)
    VK_NUMPAD7 7 key (numeric keypad)
    VK_NUMPAD8 8 key (numeric keypad)
    VK_NUMPAD9 9 key (numeric keypad)
    }
    function TFloatEdit.TextAsInteger:Integer;
    begin
     try
      Result:=Round(StrToFloat(Text));
     Except on EConvertError do
      Result:=0;
     end;
    end;
    function TFloatEdit.TextAsFloat:Extended;
    begin
     try
      Result:=StrToFloat(Text);
     Except on EConvertError do
      Result:=0.0;
     end;
    end;
    function TFloatEdit.DoKeyPress(var Message: TWMKey): Boolean;
    begin
     Result:=false;
     Message.Result:=1;
     if (StrScan(PChar(Text),'.')<>nil) and (Char(Message.CharCode) = '.' )or
         not(Char(Message.CharCode) in ['0'..'9','.'])and not (Message.CharCode in [VK_BACK]) then
      begin
         Message.Result:=0;
         Result:=true;
     end;
    end;
    procedure TFloatEdit.WMChar(var Message:TWMKey);
    begin
     if not DoKeyPress(Message) then inherited;
    end;procedure TFloatEdit.CreateParams(var Params: TCreateParams);
    const
      Alignments: array[Boolean, TAlignment] of DWORD =
        ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));begin
      inherited CreateParams(Params);
      with Params do
      begin
       case FTextAlign of
        taLeftJustify:
         begin
          Style :=Style and not ES_CENTER;
          Style :=Style and not ES_RIGHT;
          Style := Style  or ES_LEFT;      
         end;
        taRightJustify:
         begin
          Style :=Style and not ES_CENTER;
          Style :=Style and not ES_LEFT;
          Style := Style  or ES_RIGHT;
         end;
        taCenter:
         begin
          Style :=Style and not ES_LEFT;
          Style :=Style and not ES_RIGHT;
          Style := Style  or ES_CENTER;
         end;
       end;
    //    Style := Style  or FTextAlign;//Alignments[UseRightToLeftAlignment, FTextAlign];
      end;
    end;
    procedure TFloatEdit.SetTextAlign(Value:TAlignment);
    begin
      FTextAlign:=Value;
      RecreateWnd;
    end;
    constructor TFloatEdit.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);end;
    end.
    这个控件写的不成功,但可以实现您说的功能,
    您可以在运行期(必须是运行期)设置控件的TextAlign 属性为TAlignment(在DELPHI的帮助里有说明)的一个值就可以了
      

  6.   

    居中:
    SetWindowLong(Edit1.handle, GWL_STYLE,GetWindowlong(edit1.Handle, GWL_STYLE) +ES_CENTER);
    靠右:
    SetWindowLong(Edit1.handle, GWL_STYLE,GetWindowlong(edit1.Handle, GWL_STYLE) +ES_RIGHT);
    设置后,刷新一下
    Edit1.Refresh  ;
      

  7.   

    設置edit1的Align的屬性為clenter
      

  8.   

    procedure TForm1.Button1Click(Sender: TObject);
    var rect:Trect;
    dc:hdc;
    cha:pointer;
    begin
    SendMessage(edit1.Handle,EM_LIMITTEXT,30,0);
    rect:=edit1.ClientRect;
    dc:=GetDc(edit1.Handle);
    drawText(dc,'hello',5,rect,dt_center);
    end;
      

  9.   

    上面多位兄弟说的不错:只有修改或继承
        重写方法CreateParams(var Params: TCreateParams)加上居中属性.
      

  10.   

    自己写几句代码也行呀,当客户的焦点移开时区一下Text的长度,根据edit的长度计算一下,在自己加入几个空格不就行了呀。:)