The preceding implementation method is to bind the mousehover of the panel with the mouseleave event to achieve the effect similar to the VM menu.
However, this implementation has a disadvantage: if the Panel has a control, such as a button, when you move the mouse over the button, you have to respond to the Panel
Mouseleave event...
There are two solutions,
1. Rewrite the mouse binding event to add the same mousehover and mouseleave event to the Panel and all the controls above. This implementation is too troublesome. Reject...
2. Read the mouse position without stopping through a timer to determine whether the mouse is on the panel... This will have an impact on efficiency, but the effect is still unsatisfactory.
The Code is as follows:
// Put a button button1 on the panel
# Region mouse control title bar explicit
// Enter with the mouse
Private bool mentered = false;
Void timereffectick (Object sender, eventargs E)
{
Point pos2 = This. pointtoclient (cursor. position );
Point Pos = panel1.pointtoclient (cursor. position );
Bool entered = This. panel1.clientrectangle. Contains (POS );
If (entered! = Mentered)
{
Mentered = entered;
If (! Entered)
{
// Move the mouse away
Animation (false );
}
Else
{
// Hover the mouse over
If (! Ismoving)
If (this. panel1.location. Y <= 10-This. panel1.height)
Animation (true );
}
}
}
Bool updown = true;
Int adddistance = 3;
Bool ismoving = false;
System. Windows. Forms. Timer timer = new timer ();
Private void form2_load (Object sender, eventargs E)
{//
Panel1.margin = new system. Windows. Forms. Padding (0, 0, 0, 0 );
Panel1.location = new point (panel1.location. X, 10-panel1.height );
}
Private void animation (bool isdown)
{
Updown = isdown;
If (isanimation)
{
Ismoving = true;
Timer = new timer ();
Timer. interval = 50;
Timer. Tick + = new eventhandler (timer_tick );
Timer. Start ();
}
}
Void timer_tick (Object sender, eventargs E)
{
If (updown) // show
If (this. panel1.location. Y <0)
{
This. panel1.location = new point (this. panel1.location. X,
Math. Min (0, this. panel1.location. Y + adddistance ));
}
Else
{
//
Ismoving = false;
Timer. Dispose ();
}
Else // hide
{
If (this. panel1.location. Y> 10-panel1.height)
This. panel1.location = new point (this. panel1.location. X,
Math. Max (10-panel1.height, this. panel1.location. Y-adddistance ));
Else
{
Ismoving = false;
Timer. Dispose ();
}
}
}
Bool isanimation = true;
Private void button#click (Object sender, eventargs E)
{
Isanimation =! Isanimation;
}
# Endregion