如何通过使用TApplicationEvents组件检测表单调整大小END? [英] How to detect Form Resize END, maybe by using the TApplicationEvents component?

查看:61
本文介绍了如何通过使用TApplicationEvents组件检测表单调整大小END?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 10.4 VCL应用程序中,我需要检测FORM RESIZING ENDS 的时间.(例如,在用户通过拖动表格的大小尺寸来调整其大小之后).

In a Delphi 10.4 VCL Application, I need to detect when the FORM RESIZING ENDS. (E.g. after the user resized the Form by dragging its size-grip).

因此,我在窗体上放置了一个 TApplicationEvents 组件,并创建了其 OnMessage 事件处理程序,试图捕获 WM_EXITSIZEMOVE 消息:

So I have placed a TApplicationEvents component on the form and created its OnMessage event-handler, trying to catch the WM_EXITSIZEMOVE message:

procedure TformMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
  if (Msg.Message = WM_EXITSIZEMOVE) then
  begin
    CodeSite.Send('TformMain.ApplicationEvents1Message: WM_EXITSIZEMOVE');
  end;
end;

但是,在调整窗体大小之后,不会执行具有 WM_EXITSIZEMOVE 的事件处理程序.

But the event-handler with WM_EXITSIZEMOVE is not executed after resizing the Form.

那么,如何通过使用TApplicationEvents组件来检测表单调整大小" END?

So how can I detect the Form Resize END, maybe by using the TApplicationEvents component?

推荐答案

The WM_EXITSIZEMOVE message is sent directly to the window. Thus, it is not detected by the TApplicationEvents's OnMessage handler, because that only detects messages that are posted to the main message queue.

因此,您需要改写表单的 WndProc():

So, you need to override the form's WndProc() instead:

type
  TForm1 = class(TForm)
  private
  protected
    procedure WndProc(var Message: TMessage); override;
  public
  end;

implementation

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  case Message.Msg of
    WM_EXITSIZEMOVE:
      ShowMessage('Yes!');
  end;
end;

或者,您可以使用 消息程序代替:

Or, you can use a message procedure instead:

type
  TForm1 = class(TForm)
  private
  protected
    procedure WMExitSizeMove(var Message: TMessage); message WM_EXITSIZEMOVE;
  public
  end;

implementation

procedure TForm1.WMExitSizeMove(var Message: TMessage);
begin
  inherited;
  ShowMessage('Yes!');
end;

但是,请注意,此消息,顾名思义,不仅在调整窗口大小时发送,而且在移动窗口后发送.而且在这两种情况下,仅当操作涉及模态循环时.

However, beware that this message, as its name implies, is not only sent when the window has been resized, but it is also sent after the window has been moved. And in both cases, only when the operation involved a modal loop.

例如,如果通过双击其标题栏来最大化窗口,或者通过按 Shift + Win + 对,此消息根本不会发送.

For instance, if you maximize the window by double-clicking its title bar, or if you move it to a different screen by pressing Shift+Win+Right, this message isn't sent at all.

这篇关于如何通过使用TApplicationEvents组件检测表单调整大小END?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆