精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>控件开发和使用>>可以设置对齐方式的Edit

主题:可以设置对齐方式的Edit
发信人: soaringbird(假行僧*飞翔鸟)
整理人: teleme(2002-07-23 12:50:58), 站内信件
unit NewEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls;

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

    { Private declarations }
  protected
    { Protected declarations }
    procedure CreateParams(var Params: TCreateParams); override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Alignment:TAlignment read FAlignment write SetAlignment default taLeftJustify;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('New', [TNewEdit]);
end;

{ TNewEdit }


procedure TNewEdit.SetAlignment(const Value: TAlignment);
begin
  if FAlignment <> Value then
  begin
    FAlignment := Value;
    RecreateWnd();
  end;
end;
procedure TNewEdit.CreateParams(var Params: TCreateParams);
const
  Alignments: array[Boolean, TAlignment] of DWORD =
    ((ES_LEFT, ES_RIGHT, ES_CENTER),(ES_RIGHT, ES_LEFT, ES_CENTER));
  ScrollBar: array[TScrollStyle] of DWORD = (0, WS_HSCROLL, WS_VSCROLL,
    WS_HSCROLL or WS_VSCROLL);
  WordWraps: array[Boolean] of DWORD = (0, ES_AUTOHSCROLL);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    Style := Style or Alignments[UseRightToLeftAlignment, FAlignment];
  end;
end;

end.

[关闭][返回]