[Winfrom] Use a startup shortcut to open 2 different forms and share a cache space

Source: Internet
Author: User

Tag: Otherwise get value visual opens style ESS ODI pre

The reason why this function, is not want to back to the backstage and the front desk to write a set of communication mechanism in the case of lazy way!

Previously found in the main function to write methods, the second launch program to open a new form or show hidden form! Finally found that the main function opened in the new form and the original program is not to share a cache!

So think of a more crooked way, the original form to set the timer and other detection changes, the use of external file changes, the form to show, hide and open, so it is actually open on the original program of the new form!

External files can use anything, Text, config, XML and the like!

This is written in the main function, to detect whether the two-time start:

process[] Processcollection =Process.getprocessesbyname (application.companyname); //If the program process is larger than the program is already running, pop-up the message and make the action, or create the program            if(Processcollection. Length >1)            {                stringss=configurationmanager.appsettings["Mainflag"]; if(ss=="0") {Setconfigvalue ("Mainflag","1"); }                           }            Else{application.enablevisualstyles (); Application.setcompatibletextrenderingdefault (false); //Run the applicationApplication.Run (Newformclient ()); }

This is the check in the timer:

string Mainflag = Getconfigvalue ("mainflag");              if " 1 " )            {                setconfigvalue ("mainflag","3 " );                 New FormMain ();                Fm. Show ();            }

When you close the new open form, you need to mark the restore back.

Modify and read config:

        /// <summary>        ///gets the value of a node in a appsettings/// </summary>        /// <param name= "key" ></param>         Public Static stringGetconfigvalue (stringkey) {Configuration config=configurationmanager.openexeconfiguration (Configurationuserlevel.none); if(config. Appsettings.settings[key]! =NULL)                returnCONFIG. Appsettings.settings[key].            Value; Else                return string.        Empty; }        /// <summary>        ///Modify the configuration in appsettings/// </summary>        /// <param name= "key" >Key Value</param>        /// <param name= "value" >corresponding Value</param>         Public Static BOOLSetconfigvalue (stringKeystringvalue) {            Try{Configuration config=configurationmanager.openexeconfiguration (Configurationuserlevel.none); if(config. Appsettings.settings[key]! =NULL) config. Appsettings.settings[key]. Value=value; ElseCONFIG.                APPSETTINGS.SETTINGS.ADD (key, value); Config.                Save (configurationsavemode.modified); Configurationmanager.refreshsection ("appSettings"); return true; }            Catch            {                return false; }        }

Do not know whether or not to use external files in a way to achieve this effect! Or have a better way to welcome the Communication Guide!!!

[Winfrom] Use a startup shortcut to open 2 different forms and share a cache space

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.