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 ...
随机推荐
- Oracle 6 - 锁
Oracle锁没有额外的开销?Oracle的锁是怎么实现的?因为其他数据库,锁都是一种稀有资源和开销. 答:代码级实现?? 没有锁的话,并发更新就会有丢失更新的问题. 悲观锁和乐观锁 悲观锁一般用于有 ...
- 李洪强iOS开发之OC[012] -类的声明实现小结
// // main.m // 11 - 内容总结 // // Created by vic fan on 16/7/9. // Copyright © 2016年 李洪强. All righ ...
- 随机森林分类(Random Forest Classification)
其实,之前就接触过随机森林,但仅仅是用来做分类和回归.最近,因为要实现一个idea,想到用随机森林做ensemble learning才具体的来看其理论知识.随机森林主要是用到决策树的理论,也就是用决 ...
- eclipse中(装了插件m2eclipse后的)导入maven工程显示"感叹号"
有时候导入一些开源工程(maven结构的),在eclipse中(装了插件m2eclipse后的)该工程前面会有一个小的红色感叹号,但点开工程后没有发现有打小红叉的内容,这种情况其实大部分是jar包 ...
- Windows下Subversion和Apache的安装及配置(一)
1.序 Subversion可谓版本控制软件中的佼佼者,其开源性,易用性已受到众多软件开发者首选的版本控制软件.在这里我想记录我安装Subversion和Apache的过程.注意,Subversion ...
- sqlserver防止数据库挂马新尝试
想法不错,放着以后应该会有用 网站挂马非常让人头痛,每次的安全措施都是治标不治本,想找到根本原因,只能去分析你的程序源代码,由于很多网站不是一个程序员开发,很多的注入漏洞很难发现,曾经通过公共文件加入 ...
- alias 命令
功能说明:设置指令的别名. 语 法:alias[别名]=[指令名称] 参 数 :若不加任何参数,则列出目前所有的别名设置. 举 例 :ermao@lost-desktop:~$ alias ...
- GridView官方教程及示例
Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The gri ...
- html5 touch事件实现触屏页面上下滑动(二)
五一小长假哪都没去,睡了三天,今天晕晕沉沉的投入工作了,但还是做出了一点点效果 上周用html5的touch事件把简单的滑动做出来了,实现了持续页面上下滑动的效果,参考之前 的文章及代码html5 t ...
- 1002: A+B for Input-Output Practice (II)
问题描述: http://acm.wust.edu.cn/problem.php?id=1002&soj=0 代码实现: import java.util.Scanner; public cl ...