On mouse Over 
Author Message
 On mouse Over

Hi,

I was trying to insert a Onmouseover event but it is not in Delphi, I have
tried to do the same using Onmousemove but I am not able to make it run.

I have write that when the mouse is over a label (left<X<(left+Lenght) and
top<Y<(top+height)) but it doesnt work properly

Anybody, I just want to change the font color when the mouse is on the label
(like if it were a weblink)

Thanks.

Alfredo



Sat, 04 Oct 2003 03:17:51 GMT  
 On mouse Over
First of all - you missed the group. Second, you must write your own label
control but I'll do it for you:

unit HotLabel;

interface

uses Windows, Messages, StdCtrls, ExtCtrls, Classes, Forms, Controls;

THotLabel = class(TLabel)
private
    FOnMouseLeave: TNotifyEvent;
    FOnMouseEnter: TNotifyEvent;
protected
    procedure SetOnMouseEnter(const Value: TNotifyEvent);
    procedure SetOnMouseLeave(const Value: TNotifyEvent);
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
published
    property OnMouseEnter : TNotifyEvent read FOnMouseEnter write
SetOnMouseEnter;
    property OnMouseLeave : TNotifyEvent read FOnMouseLeave write
SetOnMouseLeave;
end;

implementation

procedure THotImage.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if not Enabled then Exit;
  if Assigned(FOnMouseEnter) then
    FOnMouseEnter(Self);
end;

procedure THotImage.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if not Enabled then Exit;
  if Assigned(FOnMouseLeave) then
    FOnMouseLeave(Self);
end;

end.

That's it, it's not tested. I found the CM_MOUSEENTER/LEAVE messages
somewhere in the Rx library. I assume it'll not work under plain W95.

--
Smola
--
"And once again, the day is saved"
(http://supersmola.tripod.com/index.htm)

HTH


Quote:
> Hi,

> I was trying to insert a Onmouseover event but it is not in Delphi, I have
> tried to do the same using Onmousemove but I am not able to make it run.

> I have write that when the mouse is over a label (left<X<(left+Lenght) and
> top<Y<(top+height)) but it doesnt work properly

> Anybody, I just want to change the font color when the mouse is on the
label
> (like if it were a weblink)

> Thanks.

> Alfredo



Sat, 04 Oct 2003 16:33:19 GMT  
 On mouse Over
You have to create OnMouseEnter and OnMouseLeave events, e.g.

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    MouseControl: TControl;
    OldAppIdle: TIdleEvent;
    procedure AppIdle(Sender: TObject; var Done: Boolean);
    procedure MouseEnter(Sender: TObject);
    procedure MouseLeave(Sender: TObject);
  public
    { Public declarations }
  end;

[...]

procedure TForm1.FormCreate(Sender: TObject);
begin
  MouseControl := nil;
  // Replace OnIdle event handler
  OldAppIdle := Application.OnIdle;
  Application.OnIdle := AppIdle;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  // Restore OnIdle event handler
  Application.OnIdle := OldAppIdle;
end;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
var
  P: TPoint;
  C: TControl;
begin
  // Check if current mouse control changed
  GetCursorPos(P);
  C := FindDragTarget(P, True);
  if MouseControl <> C then
  begin
    // MouseLeave event
    if MouseControl <> nil then
      MouseLeave(MouseControl);
    MouseControl := C;
    // MouseEnter event
    if MouseControl <> nil then
      MouseEnter(MouseControl);
  end;
  // Call old OnIdle event
  if Assigned(OldAppIdle) then
    OldAppIdle(Sender, Done);
end;

procedure TForm1.MouseEnter(Sender: TObject);
begin
  // Underline label on mouse enter
  if Sender = Label1 then
    Label1.Font.Style := [fsUnderline];
end;

procedure TForm1.MouseLeave(Sender: TObject);
begin
  // Restore label on mouse leave
  if Sender = Label1 then
    Label1.Font.Style := [];
end;



Quote:
> Hi,

> I was trying to insert a Onmouseover event but it is not in Delphi, I have
> tried to do the same using Onmousemove but I am not able to make it run.

> I have write that when the mouse is over a label (left<X<(left+Lenght) and
> top<Y<(top+height)) but it doesnt work properly

> Anybody, I just want to change the font color when the mouse is on the
label
> (like if it were a weblink)

> Thanks.

> Alfredo



Sat, 04 Oct 2003 16:44:17 GMT  
 On mouse Over


Wed, 18 Jun 1902 08:00:00 GMT  
 On mouse Over
thanks, I'll try them both.
I finally success with the OnmouseMove event, but is kind complex so I'll
try your suggestions.

Thanks again



Quote:
> Hi,

> I was trying to insert a Onmouseover event but it is not in Delphi, I have
> tried to do the same using Onmousemove but I am not able to make it run.

> I have write that when the mouse is over a label (left<X<(left+Lenght) and
> top<Y<(top+height)) but it doesnt work properly

> Anybody, I just want to change the font color when the mouse is on the
label
> (like if it were a weblink)

> Thanks.

> Alfredo



Mon, 06 Oct 2003 13:30:08 GMT  
 On mouse Over


Wed, 18 Jun 1902 08:00:00 GMT  
 On mouse Over
Freddy,

I know it certainly is not as clean as writing your own event handler but it is
simple.

var
  hotlabel : tlabel;

procedure Tform.labelmousemove(Sender: TObject; Shift: TShiftState; X,  Y:
Integer);
begin
  hotlabel := sender;
  hotlabel.color := clinfobk;
end;

procedure Tform.theformmousemove(Sender: TObject; Shift: TShiftState; X,  Y:
Integer);
begin
  if hotlabel <> nil then
    begin
      hotlabel.color := clbtnface;
      hotlabel := nil;
    end;
end;

Quote:

> Hi,

> I was trying to insert a Onmouseover event but it is not in Delphi, I have
> tried to do the same using Onmousemove but I am not able to make it run.

> I have write that when the mouse is over a label (left<X<(left+Lenght) and
> top<Y<(top+height)) but it doesnt work properly

> Anybody, I just want to change the font color when the mouse is on the label
> (like if it were a weblink)

> Thanks.

> Alfredo



Fri, 10 Oct 2003 18:03:09 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. mouse...need mouse!!

2. Mouse Button and Color of mouse

3. To mouse, or not to mouse. There is a question about it!

4. To mouse, or not to mouse. There is a question about it!

5. Stop responding to mouse clicks after first mouse click??? -- Desperate!!!

6. Stop responding to mouse clicks after first mouse click???

7. Have a look at this mouse unit. Does it work or not? - mouse.pas (0/1)

8. Have a look at this mouse unit. Does it work or not? - mouse.pas (1/1)

9. Keyboard/Mouse recorder required

10. Mouse wheel and lookup combo problem

11. mouse function-tpd on win2k

12. wheel mouse support in TV

 

 
Powered by phpBB® Forum Software