I need to detect OnMouseLeave
event for TDateTimePicker
component, but it doesn't contain such event in events list. Is there a way to detect it manually?
views:
347answers:
3TDateTime is not a visual component, so it would not have a mouse leave event. Can you check the actual component (is it the date time picker?) The onExit event should handle the mouse leaving a visual control.
It would also be helpful to know which version of Delphi you are using
Thanks...
Sorry I could offer more help yesterday, the computer I was on doesn't have Delphi installed. To get the Mouse Leave event for a particular control that doesn't export it, try the following. (This code is on the form holding the date time picker control)
procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnMessage := AppMsg;
// Save the windows hande of the date time picker...
DTWind := DateTimePicker1.handle;
end;
procedure TForm1.AppMsg(var Msg: TMsg; var Handled: Boolean);
begin
// If we find a mouse leave event, for the date/time picker,
// then do something
if (msg.message = 160) and
(msg.hwnd = DTWind)
then
begin
if dateTimePicker1.color = clBlue
then dateTimePicker1.Color := clRed
else dateTimePicker1.Color := clBlue;
end;
end;
Create a procedure to get application messages (AppMsg) and assign it to the OnMessage event of the application object. Save the windows handle of the dateTimePicker control.
Within the procedure, look for the mouse leave message from the DateTimePicker control, and then do whatever processing you want (if my example, I just play with the colors)
Hope this gives you a work-around.
JVCL has a datetimepicker control and it should have OnMouseEnter/OnMouseLeave events regardless of Delphi version (AFAIK all JVCL controls have those).
You can unprotect CMMouseLeave procedure.
TDateTimePicker = class(ComCtrls.TDateTimePicker)
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
end;
{ TDateTimePicker }
procedure TDateTimePicker.CMMouseLeave(var Message: TMessage);
begin
{do something};
end;