edit组件中显示的文字,如何让它居中或者居右对齐啊!
不胜感谢

解决方案 »

  1.   

    对着控件单击右键,有个 position  属性
      

  2.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      SetWindowLong(Edit1.Handle, GWL_STYLE,
        GetWindowlong(Edit1.Handle, GWL_STYLE) + ES_CENTER); //居中
      Edit1.Refresh;  SetWindowLong(Edit2.Handle, GWL_STYLE,
        GetWindowlong(Edit2.Handle, GWL_STYLE) + ES_RIGHT); //居右
      Edit2.Refresh;
    end;
      

  3.   

    var
     defstyle: dWord;
    begin
     defstyle := GetWindowLong(Edit1.Handle, GWL_STYLE);
     SetWindowLong(Edit1.Handle, GWL_STYLE, defstyle or ES_RIGHT)
    end;
      

  4.   

    重载,自己写
    [转]:将下面控件安装到你的delphi中就行了
    --------------------------------------
    unit AEdit;interfaceuses
      Windows,
      SysUtils,
      Messages,
      Classes,
      Graphics,
      Controls,
      Forms,
      Dialogs,
      Menus,
      StdCtrls,
      ExtCtrls;type
      TEoCEdit = class(TEdit)
      private
        { Private declarations }
        FAlignment: TAlignment;
      protected
        { Protected declarations }
        function GetAlignment: TAlignment; virtual;
        procedure SetAlignment(newValue: TAlignment); virtual;
        procedure CreateParams(var Params: TCreateParams); override;
      public
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        { Published properties and events }
        property Alignment: TAlignment read GetAlignment write SetAlignment;  { Published }
      end;  { TEoCEdit }procedure Register;implementationfunction TEoCEdit.GetAlignment: TAlignment;
    { Returns the value of data member FAlignment. }
    begin
      GetAlignment := FAlignment;
    end;  { GetAlignment }procedure TEoCEdit.SetAlignment(newValue: TAlignment);
    { Sets data member FAlignment to newValue. }
    begin
      if FAlignment <> newValue then
      begin
        FAlignment := newValue;
        if not (csLoading in componentstate) then ReCreateWnd;
      end;
    end;  { SetAlignment }destructor TEoCEdit.Destroy;
    begin
      inherited Destroy;
    end;  { Destroy }constructor TEoCEdit.Create(AOwner: TComponent);
    { Creates an object of type TEoCEdit, and initializes properties. }
    begin
      inherited Create(AOwner);
      { Initialize properties with default values: }
      FAlignment := taLeftJustify;
    end;  { Create }procedure TEoCEdit.CreateParams(var Params: TCreateParams);
    const
      Alignments: array[TAlignment] of WORD = (ES_LEFT, ES_RIGHT, ES_CENTER);
    begin
      inherited CreateParams(Params);
      Params.Style := Params.Style or Alignments[FAlignment];
    end;procedure Register;
    begin
      RegisterComponents('EoC', [TEoCEdit]);
    end;  { Register }end.
      

  5.   

    这段代码行 
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      SetWindowLong(Edit1.Handle, GWL_STYLE,
        GetWindowlong(Edit1.Handle, GWL_STYLE) + ES_CENTER); //居中
      Edit1.Refresh;  SetWindowLong(Edit2.Handle, GWL_STYLE,
        GetWindowlong(Edit2.Handle, GWL_STYLE) + ES_RIGHT); //居右
      Edit2.Refresh;
    end;