implementation
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
procedure TCustomEdit_R.CreateParams(var Params: TCreateParams);
const
Passwords: array[Boolean] of DWORD = (0, ES_PASSWORD);
ReadOnlys: array[Boolean] of DWORD = (0, ES_READONLY);
CharCases: array[TEditCharCase] of DWORD = (0, ES_UPPERCASE, ES_LOWERCASE);
HideSelections: array[Boolean] of DWORD = (ES_NOHIDESEL, 0);
OEMConverts: array[Boolean] of DWORD = (0, ES_OEMCONVERT);
begin
inherited CreateParams(Params);
CreateSubClass(Params, 'EDIT');
with Params do
begin
Style := Style or (ES_AUTOHSCROLL or ES_AUTOVSCROLL or ES_RIGHT );// or
{ BorderStyles[FBorderStyle] or Passwords[FPasswordChar <> #0] or
ReadOnlys[FReadOnly] or CharCases[FCharCase] or
HideSelections[FHideSelection] or OEMConverts[FOEMConvert];
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
begin
}
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
// end;
end;
end;
procedure Register;
begin
RegisterComponents('Samples', [TCustomEdit_R]);
end;
看看下面的代码,对你也许有启发!
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
i:word;
old:tfont;
begin
old:=canvas.Font;
canvas.Font:=edit1.Font;
i:=sendmessage(edit1.handle,EM_GETMARGINS,0,0);
wordrec(i).lo:=wordrec(i).lo-canvas.TextWidth(key);
sendmessage(edit1.Handle,EM_SETMARGINS,EC_LEFTMARGIN,i);
canvas.Font:=old;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:word;
begin
wordrec(i).lo:=60;
wordrec(i).hi:=0;
sendmessage(edit1.Handle,EM_SETMARGINS,EC_LEFTMARGIN,i);
end;