Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Mouse over a label and change it's color 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello All ,

I'd like to know how to detect that a mouse is over a label , and how to detect that the mouse is not over anymores. I was using the OnMouseMove , but I didn't get the effect that i'm looking for that when the mouse is over a label , change it's color.

TIA

Thor
 
Your going to need to make a new component that is a decendent of the TLabel. then add these events under the private section of the header file:

TNotifyEvent FOnMouseEnter;
TNotifyEvent FOnMouseLeave;

these under the __published:
__property TNotifyEvent OnMouseEnter = {read = FOnMouseEnter, write = FOnMouseEnter};
__property TNotifyEvent OnMouseLeave = {read = FOnMouseLeave, write = FOnMouseLeave};

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
END_MESSAGE_MAP(TComponent);

put these in the protected:
void __fastcall CMMouseEnter(Messages::TMessage &Message);
void __fastcall CMMouseLeave(Messages::TMessage &Message);




when you've got all those, go back to your .cpp file and add this:

__fastcall VpLabel::VpLabel(TComponent* Owner)
: TLabel(Owner)
{
FOnMouseEnter = 0;
FOnMouseLeave = 0;
}

void __fastcall VpLabel::CMMouseEnter(Messages::TMessage &Message)
{
if (FOnMouseEnter)
FOnMouseEnter(this);
}

void __fastcall VpLabel::CMMouseLeave(Messages::TMessage &Message)
{
if (FOnMouseLeave)
FOnMouseLeave(this);
}

Hope that helps!
Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top