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. 一些linux的问题

    本文罗列的是我在学习linux与shell编程时所遇到的一些问题.我相信既然存在问题那么就会有需求,记录于此,希望可以快速帮助到大家. 1.在vim中用“/word"查找后,vim会以棕色背 ...

  2. Android面试题基础(转)

    71道经典Android面试题和答案 1.下列哪些语句关于内存回收的说明是正确的? (b ) A. 程序员必须创建一个线程来释放内存 B.内存回收程序负责释放无用内存 C.内存回收程序允许程序员直接释 ...

  3. C Primer Plus 第4章 字符串和格式化输入/输出 编程练习

    1. #include <stdio.h> int main(void) { ]; ]; printf("请输入您的名字: "); scanf("%s&quo ...

  4. java.util.concurrent包API学习笔记

    newFixedThreadPool 创建一个固定大小的线程池. shutdown():用于关闭启动线程,如果不调用该语句,jvm不会关闭. awaitTermination():用于等待子线程结束, ...

  5. 初识Redis

    package com.wangzhu.redis; import java.util.List; import org.junit.After; import org.junit.Before; i ...

  6. codeforces D

    D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...

  7. s3cmd的安装与配置

    安装包链接:http://files.cnblogs.com/files/litao0505/s3.rar 安装S3cmd1. tar -zxf s3cmd-1.0.0.tar.gz2. mv s3c ...

  8. 是什么让 Ubuntu 选用 Qt 而不是 GTK?

    是什么让 Ubuntu 选用 Qt 而不是 GTK? 一个正在发生的事实,Ubuntu正在不断Qt化!我曾一直在抱怨的Software Center,今日一看源码,竟然有softwarecenter/ ...

  9. Android sendMessage 与 obtainMessage (sendToTarget)比较

    话说在工作中第一次接触android 的Handler 的时候,不知道怎么去关注性能. 记得当时这么写的: Message msg = new Message() msg.what = xxx; ms ...

  10. hadoop-0.23.9安装以及第一个mapreduce测试程序

    hadoop是一个能够对大量数据进行分布式处理的软件框架.它实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有着高容错性的特点,并且设计 ...