I'm doing a test VCL app with Delphi. I have an empty form with a label and i change that label value with the form FormMouseLeave
event. It works, but if i keep the left mouse button pressed while leaving the form the event is not triggered.
I tried intercept the WM_MOUSELEAVE
message, but looks its not triggered at all (well, i guess FormMouseLeave
event is based on that message)
I don't need to trigger any drag drop, i just need my event when the mouse leave my form with left click pressed, how i can do that?
This is known behavior of WM_MOUSELEAVE
message. You can circumvent it by tracking mouse movement and when mouse leaves form bounds you can trigger event yourself.
When you have mouse button down, then your window (form) has captured the mouse and will receive WM_MOUSEMOVE
events even when mouse is out of it's bounds. WM_MOUSELEAVE
message is meant for tracking mouse inside your window when you don't have mouse captured.
If you assign MouseEnter
, MouseLeave
and MouseMove
events to your form you can do something like following:
procedure TForm1.FormMouseEnter(Sender: TObject);
begin
Label1.Caption := '';
end;
procedure TForm1.FormMouseLeave(Sender: TObject);
begin
Label1.Caption := 'left';
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if not PtInRect(ClientRect, TPoint.Create(x, y)) then Label1.Caption := 'left move';
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With