C#.Net__________________________________________________________________
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace NotifyIconExample
{
public partial class NotifyIconExample : Form
{
public NotifyIconExample()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
notifyIcon1.Visible = true;
notifyIcon1.Text = "Notify Icon Example";
notifyIcon1.ShowBalloonTip(300, "Notify Icon", "Form Hidden", ToolTipIcon.Info);
notifyIcon1.ContextMenuStrip = contextMenuStrip1;
}
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == "Show Me")
{
this.Show();
notifyIcon1.Visible = false;
}
else if (e.ClickedItem.Text == "Show Date Time")
{
notifyIcon1.ShowBalloonTip(300, e.ClickedItem.Text, "Date Time: " + DateTime.Now.ToString(), ToolTipIcon.Info);
}
else if (e.ClickedItem.Text == "Exit")
{
if (MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
Application.Exit();
}
}
}
}
VB.Net_______________________________________________________________________
-----------------------------------------------------------------
(This code is converted from C# to vb.net)
-----------------------------------------------------------------
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Namespace NotifyIconExample
Partial Public Class NotifyIconExample
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.Hide()
notifyIcon1.Visible = True
notifyIcon1.Text = "Notify Icon Example"
notifyIcon1.ShowBalloonTip(300, "Notify Icon", "Form Hidden", ToolTipIcon.Info)
notifyIcon1.ContextMenuStrip = contextMenuStrip1
End Sub
Private Sub contextMenuStrip1_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs)
If e.ClickedItem.Text = "Show Me" Then
Me.Show()
notifyIcon1.Visible = False
ElseIf e.ClickedItem.Text = "Show Date Time" Then
notifyIcon1.ShowBalloonTip(300, e.ClickedItem.Text, "Date Time: " + DateTime.Now.ToString(), ToolTipIcon.Info)
ElseIf e.ClickedItem.Text = "Exit" Then
If MessageBox.Show("Are you sure you want to exit?", "Warning", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Application.[Exit]()
End If
End If
End Sub
End Class
End Namespace