WinForm Program boot and tray display, and allow a program to run

Source: Internet
Author: User

1, build a WinForm program-testiconform, change its property showintaskbar to false, so that the program will not be displayed in the taskbar; Set the MaximizeBox property to False to mask the Maximize button Change the StartPosition property to Certernscreen so that the window will be centered when the program is run.

2, in the common control in the toolbar, drag into the NotifyIcon control-notifyicon1, this is the program to run the taskbar to the right of the notification area icon display control.

3. In the toolbar, in the menu and toolbar, drag into the CONTEXTMENUSTRIP-CONTEXTMENUSTRIP1, this control is right-click the context menu.

4, right-NotifyIcon1 Select the property, the property ContextMenuStrip to Testcontextmenustrip, this time 1 and 22 steps of two controls are associated, to complete the above (3) function.

5. Right-Testcontextmenustrip Select Properties, go to items, then click "Add", here Add three menu options: Exitmenuitem, Hidemenuitem, showMenuItem, Change its Text property to: Exit, hide, and display, respectively.

 Private voidOpcvalue_load (Objectsender, EventArgs e) {             This.           Hide (); }#regionPallet handlingPrivate voidOpcvalue_formclosing (Objectsender, FormClosingEventArgs e) {E.cancel=true;        Hidemainform (); }        Private voidOpcvalue_sizechanged (Objectsender, EventArgs e) {            if( This. WindowState = =formwindowstate.minimized) {hidemainform (); }        }        Private voidShowmenuitem_click (Objectsender, EventArgs e)        {Showmainform (); }        Private voidHidemenuitem_click (Objectsender, EventArgs e)        {Hidemainform (); }        Private voidExitmenuitem_click (Objectsender, EventArgs e)        {Exitmainform (); }        #regionProcessing the display of a form hide close (exit)Private voidExitmainform () {if(MessageBox.Show ("Are you sure you want to exit the OPC data receiving program? ","Confirm Exit", Messageboxbuttons.okcancel, messageboxicon.question, messageboxdefaultbutton.button2) = =DialogResult.OK) { This. notifyicon1.visible =false;  This.                Close ();  This.                Dispose ();            Application.exit (); }        }        Private voidHidemainform () { This.        Hide (); }        Private voidShowmainform () { This.            Show ();  This. WindowState =Formwindowstate.normal;  This.        Activate (); }        #endregion        Private voidNotifyicon1_doubleclick (Objectsender, EventArgs e) {            if( This. WindowState = =formwindowstate.normal) { This. WindowState =formwindowstate.minimized;            Hidemainform (); }            Else if( This. WindowState = =formwindowstate.minimized) {showmainform (); }        }        #endregion

Run only one program run code:

usingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.Linq;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceopcvalues{Static classProgram {/// <summary>        ///The main entry point for the application. /// </summary>[STAThread]Static voidMain () {intProcesscount =0; Process[] PA= Process.getprocesses ();//gets the current process array.             foreach(Process PTestinchPA) {                if(Ptest.processname = =process.getcurrentprocess (). ProcessName) {Processcount+=1; }            }            if(Processcount >1) {MessageBox.Show (NULL,"The same program is already running, please do not run multiple programs at the same time!\n\n this program is about to quit!", Application.productname+"Exit Program", MessageBoxButtons.OK, messageboxicon.warning); //application.exit ();                return;            } application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); Application.Run (NewOpcvalue ()); }    }}

WinForm Program boot and tray display, and allow a program to run

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.