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 ...
随机推荐
- Asp.net 身份验证
Forms 验证方式对基于用户的验证授权提供了很好的支持,可以通过一个登录页面验证用户的身份,将此用户的身份发回到客户端的Cookie,之后此用户再访问这个 web应用就会连同这个身份Cookie一起 ...
- 嘿嘿,JAVA里第一次运行单元测试成功,立存
按书上写的单元测试. 居然一次过,爽!!! package org.smart4j.chapter2.test; import java.util.HashMap; import java.util. ...
- 安装ubuntu vi编辑无法正常使用的时候 如方向键变成ABCD
http://blog.sina.com.cn/s/blog_7e3f6e8f0100vkon.html 在使用ubuntu的时候,发现vi编辑模式下退格键backspace和上下左右光标移动键不能用 ...
- PKUSC 模拟赛 day2 上午总结
今天上午考得不是很好,主要还是自己太弱QAQ 开场第一题给的图和题意不符,搞了半天才知道原来是走日字形的 然后BFS即可 #include<cstdio> #include<cstr ...
- Linux基础--分类与合并命令
1.sortsort命令将许多不同的域按不同的顺序分类,sort命令的一般格式为: sort -cmu -o output_file [other options] +pos1 +pos2 input ...
- rhel-server-7.2-x86_64无法联网(VMware环境)
vim /etc/sysconfig/network-script vim ifcfg-eno16777736 (编辑网卡名) 将ONBOOT=NO更改为YES (启动network服务时是否启用该网 ...
- TCP和UDP协议的应用/参数查看
TCP发送的包有序号,对方收到包后要给一个反馈,如果超过一定时间还没收到反馈就自动执行超时重发,因此TCP最大的优点是可靠.一般网页(http).邮件(SMTP).远程连接(Telnet).文件(FT ...
- PHP的线程安全与非线程安全版本的区别
Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍. ...
- selenium--大家庭介绍
安装好配置环境后,开始我的selenium之旅.简单的了解一下色,selenium大家庭的组成. Selenium是ThoughtWorks专门为 Web 应用而开发的功能测试工具.Selenium使 ...
- dex
数字交叉连接设备(Dendenkosha Electronic Exchange),就是常说的电子交换器. 数字交叉连接设备完成的主要是STM-N信号的交叉连接功能,它是一个多端口器件,它实际上相 ...