Hi Tech Friends,
I am trying to write a small systray application which can show internet connectivity status. It works fine with balloon notification.
However, the balloon always shows on desktop behind task bar! How to set balloon always show in front?
Below is the sample code( excuse for pasting here. looks like code block paster does not work with IE8 properly):
---------------------------------------------------------------------------------------------------------
using
System;using System.Drawing;using System.Resources;using System.ComponentModel;using System.Windows.Forms;using System.Net.NetworkInformation;using System.Threading;
public class SystemTray : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon WSNotifyIcon;
private System.ComponentModel.IContainer components;
private Icon mDirIcon = new Icon(typeof(SystemTray).Assembly.GetManifestResourceStream("InternetCheck.FLGUSA02.ICO"));
public bool ShowConnectedStatus = false;
public SystemTray()
{
//constructor for the form
InitializeComponent();
//keep the form hidden
this.Hide();
IntializeConnectionCheck();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region
Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.WSNotifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.TopMost = true;
//
// WSNotifyIcon
//
this.WSNotifyIcon.Text = "Connectivity Check";
this.WSNotifyIcon.Visible = true;
this.Visible = true;
//
// SysTray
//
this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(8, 7);
this.ControlBox = false;
this.Enabled = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SystemTray";
this.Opacity = 50;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[
STAThread]
static void Main()
{
Application.Run(new SystemTray());}
public bool IsConnectionAvailable()
{
//create an instance of the System.Net.NetworkInformation Namespace
Ping ping = new Ping();
//Create an instance of the PingReply object from the same Namespace
PingReply reply;
//int variable to hold # of pings not successful
try
{
//use the Send Method of the Ping object to send the
//Ping request
reply = ping.Send(
"64.233.169.103", 10000);
//now we check the status, looking for,
//of course a Success status
if (reply.Status != IPStatus.Success)
{
//now valid ping so increment
return false;}
else
{
return true;}
}
catch (Exception err)
{
return false;
}
}
private void IntializeConnectionCheck()
{
WSNotifyIcon.Icon = mDirIcon;
WSNotifyIcon.Visible = true;
WSNotifyIcon.BalloonTipTitle = "Check Connectivity";
if (!IsConnectionAvailable()){
WSNotifyIcon.BalloonTipText = "No Internet Connection !";
WSNotifyIcon.ShowBalloonTip(10000);
ShowConnectedStatus = true;
}
else if(ShowConnectedStatus){
WSNotifyIcon.BalloonTipText =
"Now Connected !";
WSNotifyIcon.ShowBalloonTip(10000);
ShowConnectedStatus = false;
}
Thread.Sleep(10000);
IntializeConnectionCheck();
}
}