I am creating a user control (inherited from TCustomControl
) in Delphi XE2 (and had this problem in other controls), and during development I cannot click them. I know that this has to do with capturing the mouse and catching mouse events and managing them differently during development than the runtime, but I donβt know how to place them correctly. In other words, from the many works that I can think of, I cannot decide which one is the right (or most effective) way.
I'm sure there must be a very simple standard for this, most likely using ControlStyle
or CreateParams
, but don't know what.
In this particular control (and I did not see the pattern in this problem), I collect messages, including WM_NCHITTEST
and WM_LBUTTONDOWN
. At design time, the control is 100% active as if it were a run-time, and when clicked, it would execute the run-time code instead.
I have a feeling that this is in the message handler of the test message, so here is this code (some things have been renamed):
procedure TMyCustomControl.WMNCHitTest(var Message: TWMNCHitTest); var P: TPoint; Poly: TPoints; X: Integer; I: TMyCollectionItem; Ch: Bool; //Need to improve invalidation begin Ch:= False; P:= ScreenToClient(Point(Message.Pos.X, Message.Pos.Y)); for X := 0 to Items.Count - 1 do begin I:= Items[X]; Poly:= I.Points; FMouseIndex:= -1; FMouseState:= bmNone; if PointInPolygon(P, Poly) then begin //checks if point is within polygon FMouseIndex:= X; FMouseState:= bmHover; Ch:= True; Break; end; end; if Ch then Invalidate; end;
And also my control constructor (stripped):
constructor TMyCustomControl.Create(AOwner: TComponent); begin inherited; ControlStyle:= ControlStyle - [csDesignInteractive]; end;
source share