如何使TEdit的Text右对齐

解决方案 »

  1.   

    在ONEXIT事件里:
    procedure TForm1.Edit1Exit(Sender: TObject);
    begin
      setwindowlong(edit1.handle, GWL_STYLE,
          getwindowlong(edit1.handle, GWL_STYLE)
            and not ES_AUTOHSCROLL or ES_MULTILINE or ES_Right);
      edit1.invalidate;
    end;
    或:
    1. SetWindowLong(Edit1.Handle, GWL_STYLE,  GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_MULTILINE or ES_RIGHT);
    2. 写Edit1的OnKeyDown事件:
    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    begin
      if Key = VK_RETURN then
        Key := 0;
    end;