est ici un code à partir d'un projet Windows Forms fraîchement préparé, avec rien d'autre changé:Pourquoi ne puis-je pas faire en sorte que NotifyIcon soit implémenté dans une autre classe à la sortie?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Bitmap blah = new Bitmap(16, 16);
using (Graphics blah2 = Graphics.FromImage(blah))
{
blah2.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, 16, 16));
}
NotifyIcon2 n = new NotifyIcon2();
n.NotifyIcon = new NotifyIcon();
n.NotifyIcon.Icon = Icon.FromHandle(blah.GetHicon());
n.NotifyIcon.Visible = true;
}
class NotifyIcon2 : IDisposable
{
public NotifyIcon NotifyIcon { get; set; }
private bool disposed;
~NotifyIcon2()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this); // The finalise process no longer needs to be run for this
}
protected virtual void Dispose(bool disposeManagedResources)
{
if (!disposed)
{
try
{
NotifyIcon.Dispose();
}
catch { }
disposed = true;
}
}
}
}
D'après ce que je peux voir, protected virtual void Dispose
, le NotifyIcon
a déjà été éliminés quand il est exécuté (ce qui explique pourquoi je mets un essayer/attraper le bloc là), donc je ne peux rien faire à propos de son icône.
Alors, comment le faire disparaître?
Jetez un oeil sur les réponses à http://stackoverflow.com/questions/1067844/issue-with-notifyicon-not -dissappearing-on-winforms-app et voir si elles aident. Pour autant que j'ai fait des recherches, apparemment, c'est juste que Windows est distrait quand il s'agit d'icônes de notification ... – BoltClock