Delphi 鼠标右键在目标之外释放时不会放弃OnMouseUp

Delphi 鼠标右键在目标之外释放时不会放弃OnMouseUp,delphi,mouseevent,right-click,Delphi,Mouseevent,Right Click,如下所示,OnMouseUp事件被监视 当在窗体内按下鼠标左键并将其拖到窗体外,然后释放时,可以触发OnMouseUp事件 当在窗体内按下鼠标右键,并将其拖到窗体外,然后释放时,无法触发OnMouseUp事件 您能否帮助评论一下如何纠正/解决鼠标右键的这种行为 unit Unit26; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;

如下所示,OnMouseUp事件被监视

当在窗体内按下鼠标左键并将其拖到窗体外,然后释放时,可以触发OnMouseUp事件

当在窗体内按下鼠标右键,并将其拖到窗体外,然后释放时,无法触发OnMouseUp事件

您能否帮助评论一下如何纠正/解决鼠标右键的这种行为

unit Unit26;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm26 = class(TForm)
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift:
        TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form26: TForm26;

implementation

{$R *.dfm}

procedure TForm26.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift:
    TShiftState; X, Y: Integer);
begin
  ShowMessage('FormMouseUp');
end;

end.
相关代码(来自TControl)如下所示

procedure TControl.MouseUp(Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Assigned(FOnMouseUp) then FOnMouseUp(Self, Button, Shift, X, Y);
end;

procedure TControl.DoMouseUp(var Message: TWMMouse; Button: TMouseButton);
begin
  if not (csNoStdEvents in ControlStyle) then
    with Message do MouseUp(Button, KeysToShiftState(Keys) + MouseOriginToShiftState, XPos, YPos);
end;

procedure TControl.WMLButtonUp(var Message: TWMLButtonUp);
begin
  inherited;
  if csCaptureMouse in ControlStyle then MouseCapture := False;
  if csClicked in ControlState then
  begin
    Exclude(FControlState, csClicked);
    if PtInRect(ClientRect, SmallPointToPoint(Message.Pos)) then
      Click;
  end;
  DoMouseUp(Message, mbLeft);
end;

procedure TControl.WMRButtonUp(var Message: TWMRButtonUp);
begin
  inherited;
  DoMouseUp(Message, mbRight);
end;

然而,如果鼠标右键在窗体外释放,似乎不会触发WMRButtonUp。和的MSDN看起来非常相似。您是否可以帮助解释为什么会触发WMLButtonUp,但在这种情况下不会触发WMRButtonUp?

要从表单外部获取鼠标事件,必须捕获它(请参阅)。来自TControl的消息指出,这不是用鼠标右键完成的button@SirRufo谢谢你的宝贵意见!您能否帮助评论如何正确覆盖WMRMouseDown和WMRMouseUp以处理鼠标捕获DDo与另一个按钮的vcl代码相同