Click on the Panel that you created in the form, press F4 (to open the control's properties panel), in the control panel you will have the event button (the one that looks like lightning, goes to the event " MouseLeave "and give two clicks (and there are more things with mouse interactions that can help you).
The code will automatically be created:
private void panel1_MouseLeave(object sender, EventArgs e)
{
}
To "close" the Panel, you can use the following code:
this.panel1.Visible = false;
Getting this way at the end:
private void panel1_MouseLeave(object sender, EventArgs e)
{
this.panel1.Visible = false;
}