PDA

Ver la Versión Completa : Centrar el texto de un edit


Sayuri
07-12-2005, 21:22:17
Buenas amigos,
Me gustaria poder conseguir que el texto de un edit estuviera centrado siempre que se escriba algo

¿Cómo se puede conseguir?

Un saludin

dec
07-12-2005, 21:29:17
Hola,

El componente "TAlignEdit (http://roman.clubdelphi.com/index.php?pg=delphi_componentes)" escrito por roman puede ayudarte. ;)

MAXIUM
19-03-2008, 21:28:59
El enlace esta roto pero aquí el código:

Página del autor: Roman (http://romansg.net/index.php?pg=alignedit)
unit AlignEdit;

interface

uses
Windows, Classes, Controls, StdCtrls;

type
TAlignEdit = class(TEdit)
private
FAlignment: TAlignment;
procedure SetAlignment(const Value: TAlignment);

protected
procedure CreateParams(var Params: TCreateParams); override;

public
constructor Create(AOwner: TComponent); override;

published
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
end;

procedure Register;

implementation

constructor TAlignEdit.Create(AOwner: TComponent);
begin
inherited;
FAlignment := taLeftJustify;
end;

procedure TAlignEdit.CreateParams(var Params: TCreateParams);
begin
inherited;

case FAlignment of
taLeftJustify: Params.Style := Params.Style or ES_LEFT;
taRightJustify: Params.Style := Params.Style or ES_RIGHT;
taCenter: Params.Style := Params.Style or ES_CENTER;
end;
end;

{
El estilo ES_XXX se usa al crear una ventana de manera que al cambiar
aquel debemos "rehacer" la ventana con RecreateWnd.
}
procedure TAlignEdit.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;

procedure Register;
begin
RegisterComponents('Samples', [TAlignEdit]);
end;

end.