1

Somewhere in my app I have the statement RE.Lines.LoadFromStream(st) where RE is a TRichEdit control.

I have also set the event onResizeRequest that fires up on execution of the above statement but not every time although the event remains assigned.

The code is big and I can't cut a part of it to show it.

Can I add some command, for example RE.Perform(.....) that will force the control to execute the event (or even better not to use an event but a function that I will call whenever I want)?

JimPapas
  • 715
  • 2
  • 12
  • 27
  • 1
    Could you describe one specific case where the OnResizeRequest is not called? – Fabrizio Aug 30 '23 at 09:53
  • I noticed that it happens after execution of the statement `RE.Height := 0`. If I comment out this statement the event fires up again. `RE.Height := 0` is essential, I can't remove it. – JimPapas Aug 30 '23 at 10:35
  • Wouldn't it be easier to call common procedure from `OnResizeRequest` handler and after `RE.Lines.LoadFromStream` rather than emulating `WM_NOTIFY` / `CN_NOTIFY`? – Peter Wolf Aug 30 '23 at 10:56
  • @PeterWolf, I am not sure understood you. `OnRequestResize` doesn't be called after `RE.Height := 0` execution – JimPapas Aug 30 '23 at 11:14

1 Answers1

2

It seems to be an implementation detail of rich edit control that the common controls library prevents generating EN_REQUESTRESIZE notification when the width or height of the control is zero.

To force EN_REQUESTRESIZE notification, send EM_REQUESTRESIZE message to rich edit control's window. This will generate the notification regardless of the control's size.

SendMessage(RE.Handle, EM_REQUESTRESIZE, 0, 0);

CRichEditCtrl from MFC has a dedicated method RequestResize for that. To mimic that you can implement a class helper:

uses
  Vcl.ComCtrls, Winapi.RichEdit;

type
  TCustomRichEditHelper = class helper for TCustomRichEdit
  public
    procedure RequestResize;
  end;

procedure TCustomRichEditHelper.RequestResize;
begin
  if HandleAllocated then
    SendMessage(Handle, EM_REQUESTRESIZE, 0, 0);
end;

You can then call:

RE.RequestResize;
Peter Wolf
  • 3,700
  • 1
  • 15
  • 30