Thank, Anonymous Monk :) I finally figured it out. I actually had the notify=>1 option in my original script but it didn't work like expected (didn't change the background color of the label) so I removed it afterwards, thinking it was useless. Now I have the notify=>1 option and after several failed experiments, I now realize I have to add the -text => '' option in my script to make things really work.

Well, it's kind of weird that in order to change the background color of a label I have to add the quite irrelevant -text => '' option. But it does the trick

Here's the code that works for me. Please note the -text => '' option in the Change() function.:
use Win32::GUI(); use constant { TME_HOVER => 1, TME_LEAVE => 2, HOVER_DEFAULT => 0xFFFFFFFF, }; $state = 0; $mw = Win32::GUI::Window->new( -title => 'Test', -pos => [170,100], -size => [200,220], ); $label = $mw->AddLabel( -background => [0,0,255], -pos => [ 70, 60 ], -size => [50, 50 ], -notify=>1, -onMouseOver => sub { $label->Change(-background => [255,0,0],-text=>'', ); return 0; }, -onMouseOut => sub { $label->Change(-background => [0,0,255],-text=>'', ); $state=0; return 0;}, -onMouseMove => \&Move, ); $mw->Show(); Win32::GUI::Dialog(); sub Move { return unless $state == 0; $state = 1; $label->TrackMouse(100,TME_HOVER|TME_LEAVE); return 1; }

And also thanks for the use constant suggestion :)


In reply to Re^2: How do I get OnMouseOver event to work on a label? by Anonymous Monk
in thread How do I get OnMouseOver event to work on a label? by ZJ.Mike.2009

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.