VB.NET TableLayout MouseEnter and leave event -
i'm trying looks "simple" since several hours, cannot understand how it...and lurking on or different sites seems maybe not obvious.
the question simple: have tablelayoutpanel multiple rows, each 1 of them contains panel, contains several other controls.
i want when mouse enters row, row background changes , when mouse leave row, comes original color.
these simple event trappers, pnllayoutrow name of panel containing other controls:
private sub devrowmouseenter(sender system.object, e eventargs) handles pnllayoutrow.mouseenter pnllayoutrow.backcolor = drawing.color.fromargb(&hffffeeaa) end sub private sub devrowmouseleave(sender system.object, e eventargs) handles pnllayoutrow.mouseleave pnllayoutrow.backcolor = drawing.color.fromargb(&hffe7debd) end sub
the problem is: mouseenter correctly fired each time enter row, mouseleave fired mouse reach 1 of controls inside panel..that drives me crazy.
in other environment, solve placing transparent object on panel , trapping mouseenter , leave object..but seems in vb trasparent objects not exist.
hope have been clear in explanation..it pretty late in night , i'm bit tired.
thank in advance hope can me
cristiano
this version of mouse leave event checks mouse still within bounds of tablelayoutpanel , if exits without changing color
private sub devrowmouseleave(sender system.object, e eventargs) handles pnllayoutrow.mouseleave dim p point = me.pointtoclient(mouseposition) if p.y > pnllayoutrow.top , p.y < (pnllayoutrow.top + pnllayoutrow.height) , p.x > pnllayoutrow.left , p.x < (pnllayoutrow.left + pnllayoutrow.width) exit sub else pnllayoutrow.backcolor = drawing.color.fromargb(&hffe7debd) end if end sub
it seems work ok me,so hope same you.
i've had google mouse polling rates , default, in windows, it's 125hz might seem ok. however, if move mouse quickly, mouse enter , leave panel more windows can detect it. because of this, .mouseenter , .mouseleave events don't fire. have here alternative @ least detect when mouse leaves panel. add timer form called tmrpanelleave
private sub devrowmouseenter(sender system.object, e eventargs) handles pnllayoutrow.mouseenter pnllayoutrow.backcolor = drawing.color.fromargb(&hffffeeaa) tmrpanelleave.start() end sub private sub tmrpanelleave_tick(sender object, e eventargs) handles tmrpanelleave.tick dim p point = me.pointtoclient(mouseposition) if p.y > pnllayoutrow.top , p.y < (pnllayoutrow.top + pnllayoutrow.height) , p.x > pnllayoutrow.left , p.x < (pnllayoutrow.left + pnllayoutrow.width) exit sub else pnllayoutrow.backcolor = drawing.color.fromargb(&hffe7debd) tmrpanelleave.stop() end if end sub
Comments
Post a Comment