Hallo zusammen,
ich lasse mir einen BalloonTip anzeigen, allerdings habe ich Schwierigkeiten, das System-Icon (TryIcon) unten rechts verschwinden zu lassen, sobald ich die Anzeige mehrmals hintereinander aufrufe.
IDE:: VS 2012; .NET:: 4.5; Example-Tools im Anhang
Ich habe mir ein Projekt erstellt und über einen Button wird der BalloonTip angezeigt. Wenn ich nichts unternehme, verschwinden auch die TryIcons. Wird aber der Button mehrmals gedrückt oder ich klicke auf den BalloonTip, erscheinen mehrere TryIcons des BalloonTips. Selbst, wenn ich das Programm schließe.
Im Anhang das Example Tool
Hier mein Code für das Ausführen des Buttons und des Schließen des Fensters.
[highlight=csharp]
private void BtnNotifyIcon_Click(object sender, EventArgs e)
{
_windowMessage.ShowBalloonTip(
" Ruft den Rückgabewert des asynchronen Vorgangs ab, der durch das übergebene IAsyncResult dargestellt wird." +
" (Von Control geerbt.)","Titel",EnumToolTipIcon.Info,EnumSysIcon s.Question,2);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_windowMessage.DisposeBalloonTip();
}
[/highlight]
Hier der Code in dem Projekt
[highlight=csharp]
public void ShowBalloonTip(string text, string caption = "", NICON notifyIcon = NICON.None,
SYSICON sysIcons = SYSICON.Information, int seconds = 3)
{
_balloontipSeconds = seconds * 1000;
notify = new NotifyIcon();
notify.BalloonTipText = text;
notify.BalloonTipTitle = caption;
notify.BalloonTipIcon = (ToolTipIcon) notifyIcon;
notify.Icon = GetSystemIcon(sysIcons);
notify.Visible = true;
notify.ShowBalloonTip(_balloontipSeconds);
_backgroundworker1 = new BackgroundWorker();
_backgroundworker1.RunWorkerAsync();
_backgroundworker1.DoWork += Backgroundworker_DoWork;
_backgroundworker1.RunWorkerCompleted += Backgroundworker1_RunWorkerCompleted;
}
private void Backgroundworker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_backgroundworker1.Dispose();
}
private void Backgroundworker_DoWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
if (worker != null && worker.CancellationPending)
{
e.Cancel = true;
}
else
{
Thread.Sleep((_balloontipSeconds*4));
DisposeBalloonTip();
}
}
private Icon GetSystemIcon(SYSICON sysIcons)
{
switch (sysIcons)
{
case SYSICON.Application:
return SystemIcons.Application;
case SYSICON.Error:
return SystemIcons.Error;
case SYSICON.Information:
return SystemIcons.Information;
case SYSICON.Question:
return SystemIcons.Question;
case SYSICON.Shield:
return SystemIcons.Shield;
case SYSICON.Warning:
return SystemIcons.Warning;
case SYSICON.WinLogo:
return SystemIcons.WinLogo;
default:
throw new ArgumentOutOfRangeException("sysIcons", "Cannot resulve the Icon for the BalloonToolTip");
}
}
public void DisposeBalloonTip()
{
if (notify != null) notify.Dispose();
}
[/highlight]
Grüße Lerando
ich lasse mir einen BalloonTip anzeigen, allerdings habe ich Schwierigkeiten, das System-Icon (TryIcon) unten rechts verschwinden zu lassen, sobald ich die Anzeige mehrmals hintereinander aufrufe.
IDE:: VS 2012; .NET:: 4.5; Example-Tools im Anhang
Ich habe mir ein Projekt erstellt und über einen Button wird der BalloonTip angezeigt. Wenn ich nichts unternehme, verschwinden auch die TryIcons. Wird aber der Button mehrmals gedrückt oder ich klicke auf den BalloonTip, erscheinen mehrere TryIcons des BalloonTips. Selbst, wenn ich das Programm schließe.
Im Anhang das Example Tool
Hier mein Code für das Ausführen des Buttons und des Schließen des Fensters.
[highlight=csharp]
private void BtnNotifyIcon_Click(object sender, EventArgs e)
{
_windowMessage.ShowBalloonTip(
" Ruft den Rückgabewert des asynchronen Vorgangs ab, der durch das übergebene IAsyncResult dargestellt wird." +
" (Von Control geerbt.)","Titel",EnumToolTipIcon.Info,EnumSysIcon s.Question,2);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_windowMessage.DisposeBalloonTip();
}
[/highlight]
Hier der Code in dem Projekt
[highlight=csharp]
public void ShowBalloonTip(string text, string caption = "", NICON notifyIcon = NICON.None,
SYSICON sysIcons = SYSICON.Information, int seconds = 3)
{
_balloontipSeconds = seconds * 1000;
notify = new NotifyIcon();
notify.BalloonTipText = text;
notify.BalloonTipTitle = caption;
notify.BalloonTipIcon = (ToolTipIcon) notifyIcon;
notify.Icon = GetSystemIcon(sysIcons);
notify.Visible = true;
notify.ShowBalloonTip(_balloontipSeconds);
_backgroundworker1 = new BackgroundWorker();
_backgroundworker1.RunWorkerAsync();
_backgroundworker1.DoWork += Backgroundworker_DoWork;
_backgroundworker1.RunWorkerCompleted += Backgroundworker1_RunWorkerCompleted;
}
private void Backgroundworker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_backgroundworker1.Dispose();
}
private void Backgroundworker_DoWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
if (worker != null && worker.CancellationPending)
{
e.Cancel = true;
}
else
{
Thread.Sleep((_balloontipSeconds*4));
DisposeBalloonTip();
}
}
private Icon GetSystemIcon(SYSICON sysIcons)
{
switch (sysIcons)
{
case SYSICON.Application:
return SystemIcons.Application;
case SYSICON.Error:
return SystemIcons.Error;
case SYSICON.Information:
return SystemIcons.Information;
case SYSICON.Question:
return SystemIcons.Question;
case SYSICON.Shield:
return SystemIcons.Shield;
case SYSICON.Warning:
return SystemIcons.Warning;
case SYSICON.WinLogo:
return SystemIcons.WinLogo;
default:
throw new ArgumentOutOfRangeException("sysIcons", "Cannot resulve the Icon for the BalloonToolTip");
}
}
public void DisposeBalloonTip()
{
if (notify != null) notify.Dispose();
}
[/highlight]
Grüße Lerando
Comment