System Tray App : System Tray Icon « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » System Tray IconScreenshots 
System Tray App
System Tray App

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace SystemTrayApp
{
  /// <summary>
  /// Summary description for SystemTrayApp.
  /// </summary>
  public class SystemTrayApp : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Button cmdClose;
    internal System.Windows.Forms.ListBox lstFiles;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public SystemTrayApp()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #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.Label1 = new System.Windows.Forms.Label();
      this.cmdClose = new System.Windows.Forms.Button();
      this.lstFiles = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // Label1
      // 
      this.Label1.Location = new System.Drawing.Point(107);
      this.Label1.Name = "Label1";
      this.Label1.Size = new System.Drawing.Size(14016);
      this.Label1.TabIndex = 5;
      this.Label1.Text = "Recently created files:";
      // 
      // cmdClose
      // 
      this.cmdClose.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | 
                      System.Windows.Forms.AnchorStyles.Right);
      this.cmdClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdClose.Location = new System.Drawing.Point(162203);
      this.cmdClose.Name = "cmdClose";
      this.cmdClose.Size = new System.Drawing.Size(8824);
      this.cmdClose.TabIndex = 4;
      this.cmdClose.Text = "Close";
      this.cmdClose.Click += new System.EventHandler(this.cmdClose_Click);
      // 
      // lstFiles
      // 
      this.lstFiles.Anchor = (((System.Windows.Forms.AnchorStyles.Top | 
                         System.Windows.Forms.AnchorStyles.Bottom
        | System.Windows.Forms.AnchorStyles.Left
        | System.Windows.Forms.AnchorStyles.Right);
      this.lstFiles.IntegralHeight = false;
      this.lstFiles.Location = new System.Drawing.Point(1027);
      this.lstFiles.Name = "lstFiles";
      this.lstFiles.Size = new System.Drawing.Size(240168);
      this.lstFiles.TabIndex = 3;
      // 
      // SystemTrayApp
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(514);
      this.ClientSize = new System.Drawing.Size(260234);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                this.Label1,
                 this.cmdClose,
                  this.lstFiles});
      this.Font = new System.Drawing.Font("Tahoma"8.25F
                         System.Drawing.FontStyle.Regular, 
                         System.Drawing.GraphicsUnit.Point, 
                         ((System.Byte)(0)));
      this.Name = "SystemTrayApp";
      this.Text = "SystemTrayApp";
      this.ResumeLayout(false);

    }
    #endregion

    private void cmdClose_Click(object sender, System.EventArgs e)
    {
      this.Close();
    }

    public void FillList(ArrayList list)
    {
      lstFiles.DataSource = list;
    }

  }
}
//====================================================================
//====================================================================

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;


namespace SystemTrayApp
{
  public class App
  {
    // Define the system tray icon control.
    private NotifyIcon appIcon = new NotifyIcon();

    // Define the menu.
    private ContextMenu sysTrayMenu = new ContextMenu();
    private MenuItem displayFiles = new MenuItem("Display New Files");
    private MenuItem exitApp = new MenuItem("Exit");

    // Define the file system watcher, and a list to store filenames.
    private FileSystemWatcher watch = new FileSystemWatcher();
    private ArrayList newFiles = new ArrayList();

    public void Start()
    {
      // Configure the system tray icon.
      Icon ico = new Icon("icon.ico");
      appIcon.Icon = ico;
      appIcon.Text = "My .NET Application";


       // Place the menu items in the menu.
       sysTrayMenu.MenuItems.Add(displayFiles);
      sysTrayMenu.MenuItems.Add(exitApp);
      appIcon.ContextMenu = sysTrayMenu;

      // Show the system tray icon.
      appIcon.Visible = true;

      // Hook up the file watcher.
      watch.Path = "c:\\";
      watch.IncludeSubdirectories = true;
      watch.EnableRaisingEvents = true;

      // Attach event handlers.
      watch.Created += new FileSystemEventHandler(FileCreated);
      displayFiles.Click += new EventHandler(DisplayFiles);
      exitApp.Click += new EventHandler(ExitApp);

    }

    private void FileCreated(object sender, System.IO.FileSystemEventArgs e)
    {
      newFiles.Add(e.Name);
    }
    private void ExitApp(object sender, System.EventArgs e)
    {
      Application.Exit();
    }

    private void DisplayFiles(object sender, System.EventArgs e)
    {
      FileList frmFileList = new FileList();
      frmFileList.FillList(newFiles);
      frmFileList.Show();
    }

    public static void Main()
    {
      App app = new App();
      app.Start();

      // Because no forms are being displayed, you need this 
      // statement to stop the application from automatically ending.
      Application.Run();
    }

  }


}


           
       
SystemTrayApp.zip( 26 k)
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.