Recent

Author Topic: [SOLVED] SynEdit resize text  (Read 864 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 715
[SOLVED] SynEdit resize text
« on: May 29, 2023, 07:38:02 pm »
Hi,

I would like to resize the text in a TSynEdit with mouse scrolling. I have the following but it doesn't work well. If you reduce the size, the text suddenly becomes large again.

Code: Pascal  [Select][+][-]
  1. procedure TFrmMain.SynEditJsonDataMouseWheelDown(Sender: TObject;
  2.   Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
  3. begin
  4.   if (ssCtrl in Shift) and Sender.InheritsFrom(TSynEdit) then begin
  5.     TSynEdit(Sender).Font.Size := TSynEdit(Sender).Font.Size - 1;
  6.     Handled := true;
  7.   end;
  8. end;
  9.  
  10. procedure TFrmMain.SynEditJsonDataMouseWheelUp(Sender: TObject;
  11.   Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
  12. begin
  13.   if (ssCtrl in Shift) and Sender.InheritsFrom(TSynEdit) then begin
  14.     TSynEdit(Sender).Font.Size := TSynEdit(Sender).Font.Size + 1;
  15.   end;
  16. end;

It is for Windows only.
« Last Edit: June 03, 2023, 03:42:32 pm by Hansvb »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10546
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit resize text
« Reply #1 on: May 29, 2023, 08:00:01 pm »
Make sure you don't go through zero.
Negative font sizes are valid values, and the font becomes larger. (IIRC pixels vs points).

SynEdit already has zoom.

add emCtrlWheelZoom to SynEdit.MouseOptions.

Hansvb

  • Hero Member
  • *****
  • Posts: 715
Re: SynEdit resize text
« Reply #2 on: June 03, 2023, 03:42:16 pm »
Quote
add emCtrlWheelZoom to SynEdit.MouseOptions.
I had overlooked that option.
Thanks, zoom now works fine.


 

TinyPortal © 2005-2018