C # implement a tray Application

Source: Internet
Author: User

The following is my network-based applicationProgramAdapted a simple demo of the pallet program to implement the basic functions of the general pallet Program

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;

Namespace windowsapplication4
{
Public partial class form1: Form
{

Private icon mneticon = new icon ("appmain. ICO ");

Private policyicon trayicon;

Private contextmenu policyiconmnu;

Public form1 ()
{
Initializecomponent ();
Initializenotifyicon ();
}

Private void form1_load (Object sender, eventargs E)
{
This. maximizebox = false;
This. minimizebox = false;
This. windowstate = system. Windows. Forms. formwindowstate. minimized;

}

private void initializenotifyicon ()
{< br> // set attributes of the pallet Program
trayicon = new policyicon ();
trayicon. icon = mneticon;
trayicon. TEXT = "using Visual C # As a pallet program";
trayicon. visible = true;
trayicon. click + = new system. eventhandler (this. click);

//// Define a menuitem array and assign the array to the contextmenu object at the same time
Menuitem [] mnuitms = new menuitem [1];
Mnuitms [0] = new menuitem ();
Mnuitms [0]. Text = "exit system ";
Mnuitms [0]. Click + = new system. eventhandler (this. showmessage );

Policyiconmnu = new contextmenu (mnuitms );
Trayicon. contextmenu = policyiconmnu;
/// Add the set contextmenu object to the tray Program
}

private void form=formclosed (Object sender, formclosedeventargs e)
{< br> trayicon. visible = false;
}< br> Public void click (Object sender, system. eventargs e)
{< br> MessageBox. show ("Visual C # compile the Event Response in the pallet program");
}

Public void showmessage (Object sender, system. eventargs E)
{
MessageBox. Show ("you have chosen to exit the system! ");
This. Close ();
}

}
}

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.