Starting an application is system tray using NotifyIcon without
showing the window.
Requirement : To start an application directly from systemtray
without showing the window. On double clicking the icon in systemtray it should
open the URL in default web browser. On right clicking the icon in system tray
a content menu should open and on clicking the same open the URL in default web
browser.
Solution: Putting the below code in Program.cs will help you
to achieve the same.
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (NotifyIcon icon = new NotifyIcon())
{
icon.Icon = ISBot.Properties.Resources.ISChatbot;
icon.ContextMenu = new ContextMenu(new MenuItem[] {
new MenuItem("Open", (s, e) => {System.Diagnostics.Process.Start("http://rajeshkamalakshan.blogspot.in"); }),
});
icon.Visible = true;
icon.DoubleClick +=
Icon_DoubleClick;
icon.Text = "Rajesh Kamalakshan";
Application.Run();
icon.Visible = false;
}
}
private static void
Icon_DoubleClick(object sender, EventArgs e)
{
LaodInbrowser ();
}
private static void LaodInbrowser
()
{
System.Diagnostics.Process.Start("http://rajeshkamalakshan.blogspot.in");
}
No comments:
Post a Comment