Erro em Edit
Srs,
Estou apenas tentando colocar o texto que está dentro de um objeto edit alinhado a direita desse objeto.
Tentei fazer o cast assim:
Tlabel(edit1).aligment := tarightjustify
só que o conteúdo do edit não fica a direita, alguém pode me dizer como faço. A propósito, tentei fazer isso no evento onenter do edit, só que pode ser em qualquer evento.
Att
Roberto
8)
Estou apenas tentando colocar o texto que está dentro de um objeto edit alinhado a direita desse objeto.
Tentei fazer o cast assim:
Tlabel(edit1).aligment := tarightjustify
só que o conteúdo do edit não fica a direita, alguém pode me dizer como faço. A propósito, tentei fazer isso no evento onenter do edit, só que pode ser em qualquer evento.
Att
Roberto
8)
Carlosmedeiroslima
Curtidas 0
Respostas
Mkoch
19/10/2005
Ve se isto ajuda, é um componente que fiz onde só aceita números e vc pode escolher o alinhamento, estude o código, talvez te ajude, se quiseres podes até criar o teu edit que se alinha a direita ao centro etc.
unit IPDANumEdit;
interface
uses
Windows, SysUtils, Classes, Controls, StdCtrls;
type
TIPDANumEdit = class(TCustomEdit)
private
FAlignment: TAlignment;
procedure SetValue(const Value: Integer);
function GetValue: Integer;
procedure SetAlignment(const Value: TAlignment);
{ Private declarations }
protected
{ Protected declarations }
procedure KeyPress(var Key: Char); override; //Controls (TWinControl)
public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams); override;
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property Align;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
property Value: Integer read GetValue write SetValue;
property Anchors;
property AutoSelect;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
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; Tiramos a propriedade 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
uses StrUtils;
procedure Register;
begin
RegisterComponents(´IPDA´, [TIPDANumEdit]);
end;
{ TIPDANumEdit }
constructor TIPDANumEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAlignment := taLeftJustify;
end;
procedure TIPDANumEdit.CreateParams(var Params: TCreateParams);
const
Styles: array [TAlignment] of DWORD = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
inherited CreateParams(Params);
Params.Style := Params.Style or Styles[FAlignment];
if (FAlignment <> taLeftJustify) and (Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
(Win32MajorVersion = 4) and (Win32MinorVersion = 0) then
Params.Style := Params.Style or ES_MULTILINE; // necessário para Win95
end;
function TIPDANumEdit.GetValue: Integer;
begin
Result := StrToIntDef(Text, 0);
end;
procedure TIPDANumEdit.KeyPress(var Key: Char);
begin
if (Key in [´0´..´9´, 8, 13, ´-´]) then
begin
//Se for o sinal de menos
if (Key = ´-´) then
begin
//Menos só no inicio.
if SelStart > 0 then
Key := 0;
//Somente um sinal de menos
if PosEx(´-´, Text, 1) > 0 then
Key := 0;
end;//if
end//if
else
begin
Key := 0;
Exit;
end;
inherited;
end;
procedure TIPDANumEdit.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
RecreateWnd;
end;
end;
procedure TIPDANumEdit.SetValue(const Value: Integer);
begin
Text := IntToStr(Value);
end;
end.GOSTEI 0
Martins
19/10/2005
Muito interessante, vale dar uma olhada nele.
Boa sorte turma.
Boa sorte turma.
GOSTEI 0