1

If you load some text in the richedit and click left mouse button + move the mouse wheel, the text will zoom in or out, without loosing the text size formatting.

Is there an easy way to implement this functionality (zoom in/out) with some lines of code?

Thank you

ray

Gabriel Angst
  • 109
  • 1
  • 12

2 Answers2

2

You can send EM_SETZOOM to the rich edit control to sets the zoom ratio

procedure SetZoom(const RichEdit: TCustomRichEdit; const Value: Integer);
const
  EM_SETZOOM = (WM_USER + 225);
begin
  SendMessage(RichEdit.Handle, EM_SETZOOM, Value, 100);
end;

procedure TForm26.btn1Click(Sender: TObject);
begin
  SetZoom(RichEdit1, 200);
end;
RepeatUntil
  • 2,272
  • 4
  • 32
  • 57
  • 1
    `EM_ZOOM` is already defined, in `richedit.pas` (in the Source\RTL\Win folder). Also, it would be much better to define `procedure SetZoom(const hRichEdit: THandle; const Value: Integer);` to make it clear it's not a `RichEdit` (the parameter name is confusing). Your call to SetZoom would also be clearer as `SetZoom(RichEdit1.Handle, 200);`, which is the default name for a RichEdit dropped on a form. Upvoted - just some suggestions. Fee free to ignore them if you want. :-) – Ken White Oct 26 '16 at 00:47
  • 1
    @KenWhite I would suggest changing the first parameter to `T(Custom)RichEdit` instead of `THandle`. A lot of things use `THandle` but are not suitable to use `EM_SETZOOM` or even `SendMessage()`. – Remy Lebeau Oct 26 '16 at 03:45
  • @Remy: Yep. Even better. – Ken White Oct 26 '16 at 14:29
2

In Delphi XE6 and later TRichEdit has a Zoom property. Set this to the percentage of zoom that you want.

Jan Goyvaerts
  • 21,379
  • 7
  • 60
  • 72