Edit - alinhamento a direita

Top  Previous  Next

type

  TAlEdit = class(TEdit)

  private

    FAlignment: TAlignment;

    procedure SetAlignment(const Value: TAlignment);

  protected

    Procedure CreateParams(Var Params: TCreateParams); Override;

    Procedure DoEnter; Override;

  public

    Constructor Create(AOwner: TComponent); Override;

  published

    Property Alignment: TAlignment Read FAlignment Write SetAlignment                               Default taLeftJustify;

  end;

 

Constructor TAlEdit.Create(AOwner: TComponent);

begin

  Inherited Create(AOwner);

  FAlignment := taLeftJustify;

end;

 

procedure TAlEdit.CreateParams(var Params: TCreateParams);

Const

  Alignments: Array[TAlignment] of Cardinal = (ES_LEFT,ES_RIGHT,ES_CENTER);

begin

  Inherited CreateParams(Params);

  Params.Style := Params.Style AND

                  ( Not 0 ) Or

                  (Alignments[FAlignment]);

end;

 

procedure TAlEdit.DoEnter;

begin

  Inherited DoEnter;

  // Faz o Selecionado Correto quando entra no Controle

  SelStart := 0;

  SelLength := Length( Text );

end;

 

procedure TAlEdit.SetAlignment(const Value: TAlignment);

begin

  If FAlignment <> Value Then

    Begin

      FAlignment := Value;

      // Recria o Controle se mudar Alinhamento.

      If Handle <> 0 Then

        Perform(CM_RECREATEWND, 00);

    End;

end;