Easy steps to create a System Tray application with C # Z

Source: Internet
Author: User

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'll need to create the context menu for the system tray, and then after this 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

Ten namespace adsensedisabler

each {

public partial class Form1 : Form

{

+ private NotifyIcon Systrayicon;

- private ContextMenu systraymenu;

-

[STAThread]

static void Main ()

{

Application. EnableVisualStyles ();

Application. Setcompatibletextrenderingdefault (false);

Application. Run (new Form1());

(+}

-

public Form1 ()

+ {

InitializeComponent ();

-

//Create a context menu for th systray.

-

systraymenu = new ContextMenu();

sysTrayMenu.MenuItems.Add ("Enable Adsense", onenabled);

sysTrayMenu.MenuItems.Add ("Disable adsensedisabler", ondisabled);

sysTrayMenu.MenuItems.Add ("Show Panel", onshowed);

sysTrayMenu.MenuItems.Add ("Exit", OnExit);

$

PNS //Create and intialise the Tray notify icon.

example uses the standard icon but can is replaced

/ /with your own custom icon.

Systrayicon = new NotifyIcon();

systrayicon.text = "Adsense disabler";

Systrayicon.icon = new Icon(systemicons. Shield, 40, 40);

+

//Add menu to tray icon and show it.

systrayicon.contextmenu = Systraymenu;

systrayicon.visible = true;

*}

-

protected override void OnLoad (EventArgs e)

{

The Visible = true;  //Hide Form window.

ShowInTaskbar = false;    //Remove from taskbar.

-

base. OnLoad (e);

+}

About

OnExit private void (object sender, EventArgs e)

(

Application. Exit ();

*

A

onenabled private void (object sender, EventArgs e)

$ {

-

+}

the

ondisabled private void (object sender, EventArgs e)

(

the

+}

in

onshowed private void (object sender, EventArgs e)

A. {

About

--}

the

+ +}

+}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.