想置成居中,但是没有对齐方式这个属性。
又或者有没有好的替代方法?(不想有空格)
用TMemo的话,显示效果不好。
Delphi6

解决方案 »

  1.   

    type
      TEditTextAlignment = (etaLeft, etaCenter, etaRight);procedure ResetAlignment(EditHandle: THandle; FTextAlignment: TEditTextAlignment);
    var
      EditStyle: integer;
    begin
      EditStyle := GetWindowLong(EditHandle, GWL_STYLE);
      case FTextAlignment of
        etaLeft   : EditStyle := EditStyle or ES_LEFT and (not ES_CENTER) and (not ES_RIGHT);
        etaCenter : EditStyle := EditStyle and (not ES_LEFT) or ES_CENTER and (not ES_RIGHT);
        etaRight  : EditStyle := EditStyle and (not ES_LEFT) and (not ES_CENTER) or ES_RIGHT;
      end;
      SetWindowLong(EditHandle, GWL_STYLE, EditStyle);
      
    end;
      

  2.   

    看看这个
    最好自己继承TEdit做个有这功能的控件. 事实上很简单的.
    unit JackEdit;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TKeySet = (ksReturn, ksEscape);
      TKeySets = set of TKeySet;  TJackEdit = class(TEdit)
      private
        { Private declarations }
        FAlignment: TAlignment;
        FKeys: TKeySets;    procedure SetAlignment(value: TAlignment);
      protected
        { Protected declarations }
        procedure CreateParams(var Params: TCreateParams); override;
        procedure KeyPress(var Key: Char); override;
      public
        { Public declarations }
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        { Published declarations }
        property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
        property Keys: TKeySets read FKeys write FKeys;
      end;
    procedure Register;implementationprocedure TJackEdit.SetAlignment(value: TAlignment);
    begin
      if value <> FAlignment then
      begin
        FAlignment := value;
        RecreateWnd;
      end;
    end;procedure TJackEdit.KeyPress(var Key: Char);
    begin
      if ksReturn in Keys then
      begin
        if Key = Chr(Vk_Return) then
        begin
          Key := Chr(0);
          (Owner as TControl).Perform(wm_NextDlgCtl,0,0);
        end;
      end;
      if ksEscape in Keys then
      begin
        if Key = Chr(Vk_Escape) then
        begin
          Key := Chr(0);
         (Owner as TControl).Perform(wm_NextDlgCtl,1,0);
        end;
      end;
      inherited KeyPress(Key);
    end;procedure TJackEdit.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      case Alignment of
        taLeftJustify  : Params.Style := Params.Style or (ES_LEFT or Es_MULTILINE);
        taRightJustify : Params.Style := Params.Style or (ES_RIGHT or ES_MULTILINE);
        taCenter       : Params.Style := Params.Style or (ES_CENTER or Es_MULTILINE);
      end;
    end;constructor TJackEdit.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FAlignment := taLeftJustify;
    end;destructor TJackEdit.Destroy;
    begin
      inherited Destroy;
    end;procedure Register;
    begin
      RegisterComponents('Jack', [TJackEdit]);
    end;end.
      

  3.   

    这么多?记得以前我贴过,就几句;
    -------------------------------------
    如果您觉的您对Delpih感兴趣或是很想学的更好些或者是对Delphi有更深的认识,我们可以一起交流;
    呵呵
    www.nxrs.net/bbs
    谢谢,别抛砖