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

I am trying to create a custom button from a TPanel component. To do this, I provided an override for the onmousedown and onmouseup events (to make some drawings), and I used the onclick event to handle clicks.

Unfortunately, if I quickly click on my panel, every other click is β€œlost”, but I cannot understand why.

Even the lightest examples in this regard will not work. I created a new VCL application, added a list, 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 ... Every second click is ignored, but I have no idea why.

Can someone explain this please?

+6
source share
1 answer

Your panel handles double clicks when you quickly click on it. Application:

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

to display double clicks in clicks. (in your custom ControlStyle , the constructor in it).

csDoubleClicks The control can receive and respond to double-click Messages. Otherwise, double-click on clicks.

See TControl.ControlStyle

+9
source

Source: https://habr.com/ru/post/1012525/


All Articles