Comme un certain nombre d’utilisateurs je suis totalement allergique à ces icones en barre des taches qui restent visible alors qu’une application a été coupé et qui disparaissent quand on passe la souris dessus.
Si votre application a ce genre de comportement c’est que votre code a été mal pensé (au niveau des libérations de ressources notamment) ou alors que vous ne connaissez pas la classe Application. Celle-ci contient un event ApplicationExit qui se déclenche à la fermeture de l’application, quoi qu’il arrive. Pensez donc à vous y abonner et introduisez y le code servant à cacher proprement votre NotifyIcon.
En Vb il faut ouvrir le panneau propritété de votre applciation et demander à voir les events de l’applciation, on peut alors s’abonner à l’event Shutdown de l’objet MyApplication:
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
' Introduisez le code masquant votre icone
End Sub
End Class
End Namespace
En C# cela se passe dans le fichier program.cs :
namespace MyDesk.AutoLogin.App
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static Int32 Main(String[] args)
{
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
// ...
}
private static void Application_ApplicationExit(object sender, EventArgs e)
{
// Introduisez le code masquant votre icone
}
}
}