我想做一个象window自带的计算器那样的东西,可是我的edit控件输入的数字只能居左,怎么居右啊?(20分)

  • 主题发起人 主题发起人 xiaoxiami2
  • 开始时间 开始时间
X

xiaoxiami2

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个象window自带的计算器那样的东西,可是我的edit控件输入的数字只能居左,怎么居右啊?
 
嗯。。
以前贴过的
unit MyEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Menus;
type
TSetInputStyles = (stString,stInteger,stFloat,stMoney);
TSetTxtAlign=(alLeft,alRight);
type
TMyEdit = class(TEdit)
private
FInputStyle : TSetInputStyles;
FEnterTab : Boolean;
FOnKeyPress : TKeyPressEvent;
FTxtAlign:TSetTxtAlign; { Private declarations }
procedure SetInputStyle(Value : TSetInputStyles);
procedure SetEnterTab(Value : Boolean);
procedure setTxtAlign(Value:TSetTxtAlign);
protected
procedure KeyPress(var Key: Char); OverRide;
procedure CreateParams(var Params: TCreateParams); override; { Protected declarations }
public
constructor Create(AOwner : TComponent); OverRide; { Public declarations }
published
property InputStyle : TSetInputStyles Read FInputStyle Write SetInputStyle;
property EnterTab : Boolean Read FEnterTab Write SetEnterTab Default False;
property OnKeyPress : TKeyPressEvent read FOnKeyPress write FOnKeyPress;
property TxtAlign:TSetTxtAlign read FTxtAlign Write SetTxtAlign;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('MYVCL', [TMyEdit]);
end;

{ TMyEdit }

constructor TMyEdit.Create(AOwner: TComponent);
begin
inherited;
FInputStyle := stString;
FEnterTab := False;
FTxtAlign:=alLeft;
end;

procedure TMyEdit.CreateParams(var Params: TCreateParams);
begin
inherited;
if FTxtAlign = alLeft then
Params.ExStyle:=Params.ExStyle or WS_EX_LEFT
else
Params.ExStyle:=Params.ExStyle or WS_EX_RIGHT;
end;

procedure TMyEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);

if FEnterTab and (Key = #13) then
begin
PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
Key := #0;
Exit;
end;

case FInputStyle of
stInteger:
if not (Key in ['0'..'9', Chr(8)]) then Key := #0;
stFloat:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
end;
stMoney:
begin
if not (Key in ['0'..'9', '.', Chr(8)]) then Key := #0;
if (Key = '.') and (Pos(Key, Text) > 0) then Key := #0;
if (Pos('.', Text) > 0) and (Key <> Chr(8)) and
((Length(Text) - Pos('.', Text)) >= 2) then Key := #0;
end;
end;


end;

procedure TMyEdit.SetEnterTab(Value: Boolean);
begin
if FEnterTab <> Value then
FEnterTab := Value;
end;

procedure TMyEdit.SetInputStyle(Value: TSetInputStyles);
begin
if Value <> FInputStyle then
FInputStyle := Value;
end;

procedure TMyEdit.setTxtAlign(Value: TSetTxtAlign);
begin
if Value <> FTxtAlign then
FTxtAlign := Value;
end;

end.
 
天哪,我不会用!!!!!!!
 
最简单的,改用LABEL,效果和EDIT一样
 
我有一个好方法,该用Memo,只设一行高度,将Alignment设为taRightJustify不就达到效果了.
 
多人接受答案了。
 
后退
顶部