Data storage in Windows Mobile (winform) development (solving the problem of calling the method of the other party or using the data of the other Party in different forms)

Source: Internet
Author: User

Windows Mobile (winform) may encounter the following problems during development:

1. in different forms, you must call the method of the other party or use the data of the other party without knowing how to call the method. For example, in a from1, another from2 is displayed in the form of dialog. How can I call the form1 method and use the data of form1 in form2?

2. For the CS development mode, loading server data takes some time. In particular, some data is used in different forms and will be loaded the next time, resulting in reduced efficiency.

3. For the first form, you cannot exit. to display the second from, you can only remove the first form. But next time, how can I call the form that has been removed from den? For example, if the login form is the first form, how can I display the login form when I log out?

To solve the above three problems, a method to define global variables is proposed. Use global variables to store reused data, including from. In general, to solve the above problems is to solve the problem of how to manage data and share resources.

The Global static variables defined in the first form are as follows:

1 # Place Region global variables on the login page for unified management 2 // note: this interface is the basis of other interfaces. If this interface is closed, the entire program will be released, therefore, when switching the interface, 3 // cannot be closed. hiden is required. When other pages return this page, you cannot create a new object because it already exists. Otherwise, it will appear again. Therefore, you need to define a global variable, use the 4 static public logon interface login when you return to the logon page on other pages; // Global Program Management 5 // basic nurse information for global call 6 public static nurse. nurseservice. nurseinfo; // global nurse information 7 // currently operated patient 8 public static nurse. nurseservice. patient grobalpatient; // Global Patient variable. When you click patient, get 9 public static nurse. nurseservice. executiveorder [] orders; // global classification execution ticket. A patient's classification execution ticket 10 public static nurse. nurseservice. Patient [] grobalpatients; // global patient list 11 12 # endregion

Save the reference of from after the constructor or from is loaded:

1 Public login interface () 2 {3 initializecomponent (); 4 login = This; // Save the reference of this from for other windows to call 5}

When you log out, you only need to show the first window previously hidden.

1 /// <summary> 2 /// cancel 3 /// </Summary> 4 /// <Param name = "sender"> </param> 5 /// <Param name = "E"> </param> 6 private void button2_click (Object sender, eventargs e) 7 {8 logon interface. login. show (); // re-display the logon Window 9 this. close (); 10}

In general, the above method can solve the problem of calling the method of the other Party in different from and save frequently used data to static variables to be loaded from the server, it can be used multiple times to avoid loading from the server multiple times, thus improving the efficiency.

 

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.