4

I have noticed that in Delphi 2009, the text in a multi-line memo has different padding on the left from that in a single-line edit, though both are based on TCustomEdit. The exact offset depends on the font size:

alt text http://img188.imageshack.us/img188/7668/editmemo.png

I am looking for a simple way to get the memo text aligned with the same offset as edit text. If that is not possible, how about a method of calculating what the offset is going to be in pixels, given the font size, so that I could adjust the positioning of the (dynamically created and positioned) fields before displaying them? I think that in an earlier release of Delphi, the two offsets were the same.

frogb
  • 2,040
  • 15
  • 22

1 Answers1

4

There is EM_GETMARGINS. I'm not sure if that counts as "simple". :-)

EDIT: Try this:

type
  tSynMargins = record
    left, right: Word;
  end;

function GetLeftMargin(hEdit: HWND): Word;
var
  margins: Longint;
begin
  margins := SendMessage(hEdit, EM_GETMARGINS, 0, 0);
  Result := tsynMargins(Margins).left;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := IntToStr(GetLeftMargin(Edit1.Handle));
  Memo1.Text := IntToStr(GetLeftMargin(Memo1.Handle));
end;

(inspired by this)

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83