資料來源:http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=22891

1. 判斷按下滑鼠左鍵
可用Mouseup或mousedown Event

2. 判斷游標是否在TShape的範圍
可用MouseMove

3. 判斷游標進入TShape及離開可攔截CM_MOUSEENTER,CM_MOUSELEAVE

ex:
type
    TShape=class(ExtCtrls.TShape) //直接繼承修改, 不須安裝新元件
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    end;

//Enter之臨界判斷點
procedure TShape.CMMouseEnter(var Message: TMessage);
begin
    Screen.Cursor:=crHandPoint;
end;

procedure TShape.CMMouseLeave(var Message: TMessage);
begin
    Screen.Cursor:=crDefault;
end;


如此你就可看到此兩Event之功能了

2. 若要Create新元件供以後用可如下

type
    TMyShape=class(ExtCtrls.TShape) //直接繼承修改, 不須安裝新元件
    private
    FonMouseEnter:TNotifyEvent;
    FonMouseLeave:TNotifyEvent;
    protected
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    published
    property OnMouseEnter:TNotifyEvent read FonMouseEnter write FonMouseEnter;
    property OnMouseLeave:TNotifyEvent read FonMouseLeave write FonMouseLeave;
    end;
procedure TMyShape.CMMouseEnter(var Message: TMessage);
begin
    if Assigned(FOnMouseEnter) then FOnMouseEnter(self);
end;

procedure TMyShape.CMMouseLeave(var Message: TMessage);
begin
    if Assigned(FOnMouseLeave) then FOnMouseLeave(self);
end;

創作者介紹

~雲居地~

翔雲 發表在 痞客邦 PIXNET 留言(0) 人氣()