Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I created the following new component in Delphi and installed it. A new <code>TColorPanel</code> component showed up in a new <code>MyComponents</code> tab in the IDE. I then used this to put a <code>TColorPanel</code> on a new app and it responded properly to the mouse enter/leave events, changing the color as desired. I'm not sure how you made your app's panels as <code>TMyPanel</code> instead of standard <code>TPanel</code>. This is just how I tried it. I used your latest message handling code as-is.</p> <pre><code>unit ColorPanel; interface uses WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TColorPanel = class(TPanel) public constructor Create(AOwner: TComponent); override; private procedure CMMouseEnter(var msg: TMessage); message CM_MOUSEENTER; procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE; protected // procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; published // property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave; end; procedure Register; implementation procedure Register; begin RegisterComponents('MyComponents', [TColorPanel]); end; constructor TColorPanel.Create(AOwner: TComponent); begin ControlStyle := ControlStyle - [csParentBackground] + [csOpaque]; inherited; end; procedure TColorPanel.CMMouseEnter(var msg: TMessage); begin inherited; Color := clBlue; { Do Whatever } end; procedure TColorPanel.CMMouseLeave(var msg: TMessage); begin inherited; Color := clRed; { Do Whatever } end; end. </code></pre> <p>I'm not sure why yours isn't working, other than to determine how you declared your app's panels to be <code>TMyPanel</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload