C # Development Example-Custom screen Capture tool (iii) Tray icon and menu implementation of graphic Introduction

Source: Internet
Author: User

Overview

The function of adding the tray icon is to add the menu function, which can be managed by the tray icon, and the tray menu includes "Open save directory, record Flash animation, record GIF animation, delay 5 seconds, set, exit" and other functions.

System Tray

The system tray is a special area, usually at the bottom of the desktop, where users can access the programs that are running at any time. In Microsoft Windows, the system tray usually refers to the status area of the taskbar, which is often referred to as the bulletin board area on GNOME's desktop, and the system tray on the KDE desktop. In each system, the pallet is a shared area of all applications that are running in the desktop environment.

Add tray icon

In Form1 form design mode, move the mouse to the left toolbox, pop up the Toolbox main panel, find NotifyIcon in common controls, and double-click it


Double-click to find a "notifyIcon1" below the form


With "NotifyIcon1" selected, set the Text property in the Properties window on the right: Screen tool


Add icon Resource

Select Menu: Project properties and select resource to switch to Icon view


Click the Add Resource drop-down button to add an existing file


Select a pre-prepared icon file to determine


Add the following code in the "Form1_Load" event:

This.notifyIcon1.Icon = Properties.resources.cutimage;this.notifyicon1.visible = true;

Compile, run, and you can see on the taskbar that the mouse moves to the tray icon and displays the property information just set on the "screen tool".

Add Tray Menu

Open Toolbox menu and Toolbars double-click "ContextMenuStrip" to add the right-click menu


Add a menu item, that line (delimiter) just enter a minus sign to do it.


The menu text is in Chinese, so the menu name will also have Chinese, I do not want the code variable name in Chinese, so the name of the exit to "Tsmi_exit"


Double-click on the Exit menu item to add code

        private void Tsmi_exit_click (object sender, EventArgs e)        {            application.exit ();        }

Adding code in the "Form1_Load" event handling

This.notifyIcon1.ContextMenuStrip = THIS.CONTEXTMENUSTRIP1;

Compile, run, click the right mouse button on the tray icon, you can see the following menu, choose to quit, you can exit the program.


The function of the tray icon and menu is complete.

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.