unit AlignmentEdit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TInputkey = (ikNormal, ikNumberOnly); {↑通常入力/数値だけ入力} TAlignmentEdit = class(TEdit) private FAlignment: TAlignment; FInputkey: TInputkey; procedure SetAlignment(const Value: TAlignment); procedure SetInputkey(const Value: TInputkey); protected procedure CreateParams(var Params: TCreateParams); override; public constructor Create(AOwner: TComponent); override; published property Alignment: TAlignment read FAlignment write SetAlignment; property Inputkey: TInputkey read FInputkey write SetInputkey; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TAlignmentEdit]); end; { TAlignmentEdit } constructor TAlignmentEdit.Create(AOwner: TComponent); begin FAlignment := taLeftJustify; FInputkey := ikNormal; inherited; end; procedure TAlignmentEdit.CreateParams(var Params: TCreateParams); begin inherited; CreateSubClass(Params, 'EDITC'); {?} with Params do case FAlignment of taLeftJustify: Style := Style or ES_LEFT; taCenter: Style := Style or ES_CENTER; taRightJustify: Style := Style or ES_RIGHT; else Assert(false, 'FAlignmentが不正です'); end; {↑98/Me/2000/Nt4SP3以降のOS対応 それ以外の95などでは Style := Style or ES_MULTILINE or ES_RIGHT and not WS_VSCROLL and not ES_AUTOVSCROLL ; このようにすると不完全(改行が入力されてしまう)ながらOKです。} with Params do case FInputkey of ikNormal:; ikNumberOnly: Style := Style or ES_NUMBER; else Assert(false, 'FInputkeyが不正です'); end; end; procedure TAlignmentEdit.SetAlignment(const Value: TAlignment); begin if (FAlignment <> Value) then begin FAlignment := Value; inherited RecreateWnd(); {↑ウィンドウを再生成} end; end; {↓SetAlignmentと同じ処理} procedure TAlignmentEdit.SetInputkey(const Value: TInputkey); begin if (FInputkey <> Value) then begin FInputkey := Value; inherited RecreateWnd(); end; end; end.