C # pallet Program (your own)

Source: Internet
Author: User

The key to making a pallet program is the policyicon control in.

In this example, the maximize and minimize buttons are hidden. The close button becomes hidden. Double-click the tray icon to display the main form. Right-click the pop-up menu.

1,

Drag policyicon1 in the C # interface, set relevant attributes (I am a beginner), or write in the code

Three balloon * attributes are the icons, content, and title of the tray bubble (for example, the formclosing event below)

The contextmenustrip attribute is the pop-up window associated with the right-click tray icon to be used below

The icon attribute adds an icon to the tray.

The text attribute is the prompt message when the mouse stays on the tray icon.

2,

Drag a contextmenustrip1 in the interface and add "" and "exit"

All code:

Using system;

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

Namespace Test
{
Public partial class form16 Tray: Form
{
Public form16 tray ()
{
Initializecomponent ();
}

Private void form16 tray _ load (Object sender, eventargs E)
{
// This. windowstate = system. Windows. Forms. formwindowstate. minimized;
This. maximizebox = false;
This. minimizebox = false;
}

Private void tooltoolstripmenuitem_click (Object sender, eventargs E)
{
// This. windowstate = system. Windows. Forms. formwindowstate. normal;
This. Show ();
}

Private void exit toolstripmenuitem_click (Object sender, eventargs E)
{
Yyicon1.dispose (); // release the tray Resource
Application. Exit (); // release all resources

}

Private void form16 tray _ formclosing (Object sender, formclosingeventargs E)
{
If (E. closereason = closereason. userclosing)
{
E. Cancel = true;
This. Hide ();
Policyicon1.balloontiptitle = "title ";
Policyicon1.balloontiptext = "the program is still running..." + "\ r \ n" + "click the tray icon to restore the window .";
Notifyicon1.showballoontip (2000 );
}
}

Private void policyicon#doubleclick (Object sender, eventargs E)
{
This. Show ();
}
}

}

Reprinted E. closereason attributes

If (E. closereason! = System. Windows. Forms. closereason. windowsshutdown)
{
               E. Cancel = true;
               This. windowstate = system. Windows. Forms. formwindowstate. minimized;
}

E. closereason attribute, whose value is of the closereason Enumeration type

Member Name Description
Applicationexitcall    The exit method of the application class is called. 
Formownerclosing       The owner form is being closed.
Mdiformclosing         The parent form of this multi-Document Interface (MDI) form is being closed.
None                   The reason for closing is undefined or cannot be determined.
Taskmanagerclosing Microsoft Windows
                         The task manager is shutting down the application.
Userclosing            The user is closing the form through the user interface (UI). For example, by clicking the close button in the form window, you can select the close button in the window control menu, you can also disable the function by pressing Alt + F4.
Windowsshutdown        The operating system is shutting down all applications to prepare for shutdown.

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.