Introduction
Standard NotificationIcon ToolTip is only 64 chars wide, and BalloonTip
is too intrusive and inflexible to use. I have written my own version of a tooltip that gives me more text and is easy to use and unobtrusive.
Background
This code uses standard WinForms controls and techniques. I looked around and found esoteric implementations using PInvoke and the like. So I created this simpler (at least for me) way of giving me what I want.
Here is a bitmap of what it looks like while hovering over an icon:
Using the Code
The code is just a method (InfoTip
) and some event handlers. You will note that it is simple to use and hopefully it will give you some ideas to take it further. It can certainly be expanded to have other controls and functionality. I should also mention that this is my first article, so please forgive me if I missed anything in the way of article entry etiquette.
private void InfoTip(int theTimeOut)
{
Point aXY = Cursor.Position;
_InfoTipForm = new Form();
_InfoTipForm.FormClosing +=
new FormClosingEventHandler(_InfoTipForm_FormClosing);
_InfoTipForm.Load += new EventHandler(_InfoTipForm_Load);
_InfoTipForm.FormBorderStyle = FormBorderStyle.None;
_InfoTipForm.BackColor = Color.Cornsilk;
_InfoTipForm.ControlBox = false;
_InfoTipForm.MaximizeBox = false;
_InfoTipForm.MinimizeBox = false;
_InfoTipForm.Width = 0; _InfoTipForm.Height = 0; _InfoTipForm.TopMost = true;
_InfoTipForm.ShowInTaskbar = false;
_InfoTipForm.Visible = true;
Label aInfoTip = new Label();
aInfoTip.BackColor = Color.Cornsilk;
aInfoTip.ForeColor = Color.Black;
aInfoTip.Font = new Font("Arial", 9, FontStyle.Regular);
aInfoTip.AutoSize = true;
aInfoTip.Location = new Point(0, 0);
aInfoTip.TextAlign = ContentAlignment.MiddleLeft;
aInfoTip.Visible = true;
aInfoTip.Text = _NotifyText;
aInfoTip.Refresh();
_InfoTipForm.Controls.Add(aInfoTip);
_InfoTipForm.Width = aInfoTip.Width;
_InfoTipForm.Height = aInfoTip.Height;
if(Screen.PrimaryScreen.Bounds.Width - aXY.X < _InfoTipForm.Width)
_InfoTipForm.DesktopLocation =
new Point(aXY.X - _InfoTipForm.Width, aXY.Y - 34);
else
_InfoTipForm.DesktopLocation = new Point(aXY.X, aXY.Y - 34);
_InfoTipForm.Refresh();
_InfoTipForm.Show();
_TipWait.WaitOne(theTimeOut * 1000, false);
_InfoTipForm.Close();
_TipWait.Reset();
}
Form _InfoTipForm;
bool _isCanShowInfoTip=true;
ManualResetEvent _TipWait=new ManualResetEvent();
private void _InfoTipForm_Load(object sender, EventArgs e)
{
_isCanShowInfoTip = false;
}
private void _InfoTipForm_FormClosing(object sender, FormClosingEventArgs e)
{
_isCanShowInfoTip = true;
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
_isCanShowInfoTip = false;
_TipWait.Set();
}
private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
{
if(_isCanShowInfoTip && !contextMenuStrip1.Visible)
InfoTip(3);}
Points of Interest
This is just a simple implementation for my own needs, but you could certainly take this and expand on it, make it more robust for your needs.