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 ...
随机推荐
- POJ 3440 Coin Toss(求概率)
题目链接 题意 :把硬币往棋盘上扔,分别求出硬币占1,2,3,4个格子的时候的概率. 思路 : 求出公式输出,不过要注意输出格式,我还因为输入的时候用了int类型错了好几次..... #include ...
- hdu 3758 Factorial Simplification
这题主要是质因数分解!! 求出每个因子的幂,如果有负数,则输出-1: 如果2的幂数为0,这输出0: 最后就是开始凑阶乘了…… #include<iostream> #include< ...
- Python str字符串常用到的函数
# -*- coding: utf-8 -*- x='pythonnnnnnoooo' print type(x) # <type 'str'> 输出类型 print x.capitali ...
- 常用的Linux终端
常用的Linux终端 gnome-terminal (Gnome标配) xfce4-terminal (XFCE4标配) lxterminal (LXDE标配) konsole (KDE标配) 前面3 ...
- Ado.Net小练习03(省市联动)
前台界面: 后台代码: namespace _04省市联动 { public partial class Form1 : Form { public ...
- Haxe - Actuate.Tween
方法解释: Actuate.tween( target : Dynamic , duration : Float , properties : Dynamic , ?overwrite : Bool ...
- 使用 Async 和 Await 的异步编程
来自:http://msdn.microsoft.com/library/vstudio/hh191443 异步对可能起阻止作用的活动(例如,应用程序访问 Web 时)至关重要. 对 Web 资源 ...
- html 表单笔记
表单 表单中主要包括下列元素: button——普通按钮radio ——单选按钮checkbox——复选框select ——下拉式菜单text ——单行文本框textarea——多行文本框s ...
- 20-语言入门-20-Financial Management
题目地址: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=72 描述Larry graduated this year and fina ...
- NFC(3)Android上的NFC,开启NFC,3种NDEF数据
Android对NFC技术的支持 Android2.3.1(API Level = 9)开始支持NFC技术,但Android2.x和Android3.x对NFC的支持非常有限.而从Android4.0 ...