Hiding the C# application to the system tray is quiet straight forward. With a few line of codes in C# and you can accomplish this. First you will need to create the context menu for the system tray, then after that you need to create the notify icon. The next step is just enable the system icon. Here is the sample code below.

1 using System;

2 using System.Collections.Generic;

3 using System.ComponentModel;

4 using System.Data;

5 using System.Drawing;

6 using System.Linq;

7 using System.Text;

8 using System.Windows.Forms;

9

10 namespace AdsenseDisabler

11 {

12     public partial class Form1 : Form

13     {

14         private NotifyIcon  sysTrayIcon;

15         private ContextMenu sysTrayMenu;

16

17         [STAThread]

18         static void Main()

19         {

20             Application.EnableVisualStyles();

21             Application.SetCompatibleTextRenderingDefault(false);

22             Application.Run(new Form1());

23         }

24

25         public Form1()

26         {

27             InitializeComponent();

28

29             // Create a context menu for th systray.

30

31             sysTrayMenu = new ContextMenu();

32             sysTrayMenu.MenuItems.Add("Enable Adsense", OnEnabled);

33             sysTrayMenu.MenuItems.Add("Disable AdsenseDisabler", OnDisabled);

34             sysTrayMenu.MenuItems.Add("Show Panel", OnShowed);

35             sysTrayMenu.MenuItems.Add("Exit", OnExit);

36

37             // create and intialise the tray notify icon.

38             // This example uses the standard icon but can be replaced

39             // with your own custom icon.

40             sysTrayIcon = new NotifyIcon();

41             sysTrayIcon.Text = "Adsense Disabler";

42             sysTrayIcon.Icon = new Icon(SystemIcons.Shield, 40, 40);

43

44             // Add menu to tray icon and show it.

45             sysTrayIcon.ContextMenu = sysTrayMenu;

46             sysTrayIcon.Visible = true;

47         }

48

49         protected override void OnLoad(EventArgs e)

50         {

51             Visible       = true; // Hide form window.

52             ShowInTaskbar = false; // Remove from taskbar.

53

54             base.OnLoad(e);

55         }

56

57         private void OnExit(object sender, EventArgs e)

58         {

59             Application.Exit();

60         }

61

62         private void OnEnabled(object sender, EventArgs e)

63         {

64

65         }

66

67         private void OnDisabled(object sender, EventArgs e)

68         {

69

70         }

71

72         private void OnShowed(object sender, EventArgs e)

73         {

74

75         }

76

77     }

78 }

Easy steps to create a System Tray Application with C# z的更多相关文章

  1. System.InvalidOperationException: 'Cannot create more than one System.Windows.Application instance in the same AppDomain.'

    System.Windows.Application is a singleton: its constructor must only be invoked once (including App. ...

  2. 6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python)

    6 Easy Steps to Learn Naive Bayes Algorithm (with code in Python) Introduction Here’s a situation yo ...

  3. System.Windows.Application.Current.Dispatcher.BeginInvoke

    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        ...

  4. ArcEngine编辑保存错误:Unable to create logfile system tables

    通过ArcEngine对多个SDE中多个图层进行批量编辑处理,其中有部分图层在结束编辑的时候出现错误提示(部分图层可以,只有两个数据较多的图层保存失败). 错误信息:Unable to create ...

  5. 转载:10 Easy Steps to a Complete Understanding of SQL

    10 Easy Steps to a Complete Understanding of SQL 原文地址:http://tech.pro/tutorial/1555/10-easy-steps-to ...

  6. 10 Easy Steps to a Complete Understanding of SQL

    原文出处:http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql(已经失效,现在收集如下) Too ...

  7. Creating a NuGet Package in 7 easy steps - Plus using NuGet to integrate ASP.NET MVC 3 into existing Web Forms applications

    UPDATE: Check out my follow up post where I remove the need for editing the Global.asax.cs and show ...

  8. Switching from Redhat Linux to Oracle Linux in about 5,000 easy steps

    Wayback When I remember being at Oracle Open World when Larry Ellison unveiled Oracle Enterprise Lin ...

  9. create Context Menu in Windows Forms application using C# z

    In this article let us see how to create Context Menu in Windows Forms application using C# Introduc ...

随机推荐

  1. Android 调节当前Activity的屏幕亮度

    调节的关键代码: WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.screenB ...

  2. lintcode:Plus One 加一

    题目: 加一 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照大小进行排列,最大的数在列表的最前面. 样例 给定 [1,2,3] 表示 123, 返回 [1,2,4 ...

  3. Java学习笔记之:Java简介

    一.引言 Java是由Sun Microsystems公司于1995年5月推出的Java面向对象程序设计语言和Java平台的总称.由James Gosling和同事们共同研发,并在1995年正式推出. ...

  4. arcengine C# 读写lyr(转)

    写lyr { IFeatureLayer LineLayer = axMapControl1.get_Layer(0) as IFeatureLayer;            ILayerFile ...

  5. Java NIO原理图文分析及代码实现

    原文: http://weixiaolu.iteye.com/blog/1479656 目录: 一.java NIO 和阻塞I/O的区别      1. 阻塞I/O通信模型      2. java ...

  6. C++:对象的初始化和构造函数

    对象的初始化和构造函数 构造函数:是一种特殊的成员函数,它主要用于为对象分配空间,进行初始化.构造函数 的名字必须与类名相同,它不要用户来调用,而是在建立对象时自动执行的 形式一: 类名 对象名(实参 ...

  7. Java API —— 网络编程

    1.网络编程概述     1)网络编程概述     · 计算机网络         是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通 ...

  8. 如何创建支持Eclipse IDE的Maven项目

    使用Maven创建的项目是不支持任何IDE的,不能导入IDE中,因为项目格式都不符合特定IDE的格式要求,那么如何创建符合IDE要求的项目呢? 1.使用mvn eclipse:eclipse 命令把项 ...

  9. 【问题】和NULL比较遇到的问题

    1.问题描述: select FName from teacher where FId not in( select distinct FTeacherId from student ) 子查询返回的 ...

  10. 转:java两个jre目录和三个lib目录

    lib目录下放置着jar包.程序中的import语句找的就是这些文件!例如:import javax.servlet.RequestDispatcher;    问题在于,在cmd模式下编译,系统会提 ...