当鼠标按钮在目标外释放时,它不会给出OnMouseUp

时间:2014-08-24 21:28:46

标签: delphi mouseevent right-click

如下所示,监控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;

但是,如果在窗体外释放ight鼠标按钮,似乎不会触发WMRButtonUp。 WM_LBUTTONUPWM_RBUTTONUP的MSDN看起来非常相似。你能帮忙评论一下为什么会激发WMLButtonUp但是在这种情况下不会触发WMRButtonUp吗?

0 个答案:

没有答案