unit Newpanel; interface Uses WinTypes, Classes, Controls, StdCtrls, ExtCtrls; Type tHotSpotClickEvent = Procedure ( Sender : tObject;Button : tMouseButton;Shift : tShiftState ) Of Object; TNewPanel = Class ( tPanel )PrivatefHotSpotClick : tHotSpotClickEvent;fHotSpot : tRect;fInHotSpot : Boolean; Function GetHotSpotTop : Word;Function GetHotSpotLeft : Word;Function GetHotSpotWidth : Word;Function GetHotSpotHeight : Word; Procedure SetHotSpotTop ( Value : Word );Procedure SetHotSpotLeft ( Value : Word );Procedure SetHotSpotWidth ( Value : Word );Procedure SetHotSpotHeight ( Value : Word );ProtectedProcedure Paint; override;Procedure MouseDown ( Button : tMouseButton; Shift : tShiftState; X, Y : Integer ); override;Procedure MouseUp ( Button : tMouseButton; Shift : tShiftState; X, Y : Integer ); override;PublicProcedure Click; override; Property HotSpot : tRect Read fHotSpot Write fHotSpot;PublishedProperty hsTop : Word Read GetHotSpotTop Write SetHotSpotTop;Property hsLeft : Word Read GetHotSpotLeft Write SetHotSpotLeft;Property hsWidth : Word Read GetHotSpotWidth Write SetHotSpotWidth;Property hsHeight : Word Read GetHotSpotHeight Write SetHotSpotHeight; Property OnHotSpot : tHotSpotClickEvent Read fHotSpotClick Write fHotSpotClick;End; Procedure Register; implementation Uses WinProcs, Graphics; Procedure Register; Begin RegisterComponents('Custom',[TNewPanel]);End; Procedure TNewPanel.MouseDown ( Button : tMouseButton; Shift : tShiftState;X, Y : Integer );Begin If PtInRect ( fHotSpot, Point ( X, Y ) ) AndAssigned ( fHotSpotClick ) ThenfInHotSpot := True;Inherited MouseDown ( Button, Shift, X, Y );End; Procedure TNewPanel.MouseUp ( Button : tMouseButton; Shift : tShiftState;X, Y : Integer );Begin Inherited MouseUp ( Button, Shift, X, Y ); If fInHotSpot ThenBeginIf Assigned ( fHotSpotClick ) ThenfHotSpotClick ( Self, Button, Shift );fInHotSpot := False;End;End; Procedure TNewPanel.Click; Begin If Not fInHotSpot ThenInherited Click;End; Procedure TNewPanel.Paint; Var OldStyle : tPenStyle;Begin Inherited Paint; If csDesigning in ComponentState ThenBeginOldStyle := Canvas.Pen.Style;Canvas.Pen.Style := psDash;Canvas.Rectangle ( HotSpot.Left, HotSpot.Top, HotSpot.Right, HotSpot.Bottom );Canvas.Pen.Style := OldStyle;End;End; Procedure TNewPanel.SetHotSpotTop ( Value : Word ); Begin fHotSpot.Bottom := fHotSpot.Bottom + Value - fHotSpot.Top;fHotSpot.Top := Value;Paint;End; Procedure TNewPanel.SetHotSpotLeft ( Value : Word ); Begin fHotSpot.Right := fHotSpot.Right + Value - fHotSpot.Left;fHotSpot.Left := Value;Paint;End; Procedure TNewPanel.SetHotSpotWidth ( Value : Word ); Begin fHotSpot.Right := fHotSpot.Left + Value;Paint;End; Procedure TNewPanel.SetHotSpotHeight ( Value : Word ); Begin fHotSpot.Bottom := fHotSpot.Top + Value;Paint;End; Function TNewPanel.GetHotSpotTop : Word; Begin Result := fHotSpot.TopEnd; Function TNewPanel.GetHotSpotLeft : Word; Begin Result := fHotSpot.Left;End; Function TNewPanel.GetHotSpotWidth : Word; Begin Result := fHotSpot.Right - fHotSpot.Left;End; Function TNewPanel.GetHotSpotHeight : Word; Begin Result := fHotSpot.Bottom - fHotSpot.Top;End; End. |
Надеюсь, с моей помощью вы найдете правильное направление,
Robert Wittig [000547]