Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Compile with:
- // csc /target:winexe SysTray.cs
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace MyTrayApp {
- public class SysTrayApp : Form {
- [STAThread]
- public static void Main() {
- Application.Run(new SysTrayApp());
- }
- private NotifyIcon trayIcon;
- private ContextMenu trayMenu;
- public SysTrayApp() {
- // Create a simple tray menu with only one item.
- trayMenu = new ContextMenu();
- trayMenu.MenuItems.Add("Exit", OnExit);
- // Create a tray icon. In this example we use a standard system icon
- trayIcon = new NotifyIcon();
- trayIcon.Text = "MyTrayApp";
- trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
- // Add menu to tray icon and show it.
- trayIcon.ContextMenu = trayMenu;
- trayIcon.Visible = true;
- }
- protected override void OnLoad(EventArgs e) {
- Visible = false; // Hide form window.
- ShowInTaskbar = false; // Remove from taskbar.
- base.OnLoad(e);
- }
- private void OnExit(object sender, EventArgs e) {
- Application.Exit();
- }
- protected override void Dispose(bool isDisposing) {
- if (isDisposing) {
- trayIcon.Dispose(); // Release the icon resource.
- }
- base.Dispose(isDisposing);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement