Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot catch all clicks when using onmousedown, onmouseup and click events

I'm trying to create a custom button out of a TPanel component. For this, I have provided an override for the onmousedown and onmouseup events (to do some drawing), and I've used the onclick event to handle the clicks.

Unfortunately, if I rapidly click my panel, every other click is "lost", but I can't figure out why.

Even the easiest of examples fails in this regard. I created a new VCL application, added a listbox, one panel, and implemented the events as follows:

procedure TForm1.Panel1Click(Sender: TObject);
begin
  listbox1.Items.Add('click');
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  listbox1.Items.Add('mouse down');
end;

procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  listbox1.Items.Add('mouse up');
end;

The result is as follows:

mouse down
click
mouse up
mouse down
mouse up

etcetera... Each second click is disregarded, but I have no idea why.

Can anybody explain this please?

like image 550
Joe Avatar asked Nov 21 '16 11:11

Joe


1 Answers

Your panel is processing double-clicks when you rapidly click on it. use:

Panel1.ControlStyle := Panel1.ControlStyle - [csDoubleClicks]

to map double-clicks into clicks. (in your custom control set ControlStyle in it's constructor).

csDoubleClicks The control can receive and respond to double-click messages. Otherwise, map double-clicks into clicks.

See TControl.ControlStyle

like image 94
kobik Avatar answered Sep 22 '22 05:09

kobik