Easy steps to create a System Tray Application with C# z
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的更多相关文章
- 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. ...
- 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 ...
- System.Windows.Application.Current.Dispatcher.BeginInvoke
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => ...
- ArcEngine编辑保存错误:Unable to create logfile system tables
通过ArcEngine对多个SDE中多个图层进行批量编辑处理,其中有部分图层在结束编辑的时候出现错误提示(部分图层可以,只有两个数据较多的图层保存失败). 错误信息:Unable to create ...
- 转载: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 ...
- 10 Easy Steps to a Complete Understanding of SQL
原文出处:http://tech.pro/tutorial/1555/10-easy-steps-to-a-complete-understanding-of-sql(已经失效,现在收集如下) Too ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- http://www.oschina.net/translate/elasticsearch-getting-started?cmp
http://www.oschina.net/translate/elasticsearch-getting-started?cmp
- lintcode :最大子数组
题目: 最大子数组 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和. 样例 给出数组[−2,2,−3,4,−1,2,1,−5,3],符合要求的子数组为[4,−1,2,1],其最大和为6 ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- lintcode:Coins in a Line 硬币排成线
题目 硬币排成线 有 n 个硬币排成一条线.两个参赛者轮流从右边依次拿走 1 或 2 个硬币,直到没有硬币为止.拿到最后一枚硬币的人获胜. 请判定 第一个玩家 是输还是赢? 样例 n = 1, 返回 ...
- utf-8中的汉字占用多少字节
转载:http://blog.csdn.net/chummyhe89/article/details/7777613 占2个字节的:〇 占3个字节的:基本等同于GBK,含21000多个汉字 占4个字节 ...
- python各种类型转换-int,str,char,float,ord,hex,oct等
int(x [,base ]) 将x转换为一个整数 long(x [,base ]) 将x转换为一个长整数 float(x ) 将x转换到 ...
- 随机森林——Random Forests
[基础算法] Random Forests 2011 年 8 月 9 日 Random Forest(s),随机森林,又叫Random Trees[2][3],是一种由多棵决策树组合而成的联合预测模型 ...
- (七)CSS定位(Positioning)
CSS定位属性允许对元素进行定位. 一切皆为框: div.h1或p元素常被称为块级元素,而span和strong等元素成为行内元素,但是可是使用 display 属性改变框的类型,将display设置 ...
- MySql开启跟踪
使用 show variables like '%log%'; 查看general_log.log_output.general_log_file 更新为 set global general_log ...
- HBase学习笔记
关键类: HBaseAdmin 管理Hbase的,主要负责DDL操作 HTable 管理表中数据,主要负责DML操作 1.为了避免热点,更多的建表方法 在Shell中: },{SPLITS=>[ ...