. Net CF program startup and exit sequence

Source: Internet
Author: User

We are trying to close someProgramFirst, click'X'Or'OK'To exit the program (some programs willFormOrMenuTo exit the Program),. Net cfProcessing'X'And'OK'Click'X'The program form is not displayed but is minimized, but the program is still running. Click'OK'CallThis. Close ();


However, many users get used to PC operations and think that they quit the program after clicking 'x. However, developers can still do some processing to click 'x' and exit the program completely.

Next, let's take a look at the program startup and exit examples to illustrate the program startup sequence and exit sequence!

Start and exit the program order code
Public Form1 ()
{
Initializecomponent ();
Showdebug ( " Form1 Constructor " );
}

//Mark the order of startup and exit
Private IntM_index= 0;

private void form1_load ( Object sender, eventargs e)
{< br> showdebug ( " form1_load " );
}

private void form1_closing ( Object sender, canceleventargs e)
{< br> showdebug ( " form1_closing " );
}

private void formshortclosed ( Object sender, eventargs e)
{< br> showdebug ( " form1_closed " );
}

private void form1_activated ( Object sender, eventargs e)
{< br> showdebug ( " form1_activated " );
}

private void formshortdeactivate ( Object sender, eventargs e)
{< br> showdebug ( " formatedeactivate " );
}

protected override void onload (eventargs E)
{< br> showdebug ( " onload " );
base . onload (E);
}

protected override void onclosing (canceleventargs E)
{< br> showdebug ( " onclosing " );
base . onclosing (E);
}

protected override void onclosed (eventargs E)
{< br> showdebug ( " onclosed " );
base . onclosed (E);
}

protected override void onactivated (eventargs E)
{< br> showdebug ( " onactivated " );
base . onactivated (E);
}

protected override void ondeactivate (eventargs E)
{< br> showdebug ( " ondeactivate " );
base . ondeactivate (E);
}

private void showdebug ( string funcname)
{< br> system. diagnostics. debug. writeline ( + m_index ). tostring () + " - " + funcname );
}< br>


Note:
Before explaining this, I 'd like to explain Form1_load And Onload Differences: In the base class Onload The function triggers an event call. Form1_load . If you rewrite Onload Function (not called Base. onload (E ); Define your own operations during program loading ).CodeIt will not be executed, that is Form1_load Will not be executed .
The same applies to other functions.

1. First, check the program startup sequence:

1-form1 Constructor
2-onload
3-form1_load
4-onactivated
5-form1_activated


We can know that the program starts according to the "Constructor-Load-activated.



2.Then click'X'Exit sequence after the number:

1-form1 Constructor
2-onload
3-form1_load
4-onactivated
5-form1_activated

6-ondeactivate
7-form1_deactivate

The exit order of clicking 'X' is "deactivate", but it does not enter onclosing or onclosed, then we can understand why the program does not exit after clicking 'x. So what should we do? It's very simple. Because the program enters deactivate after 'x', weCall this. Close () in ondeactivate or formatedeactivate to accessOnclosing and onclosed are in progress, and then some exit processing is done in onclosing and onclosed. That's it!


3. Click the exit sequence after 'OK '.

1-form1 constructor
2-onload
3-form1_load
4-onactivated
5 -form1_activated

6-onclosing
7-form1_closing
8-onclosed
9-form1_closed
10-ondeactivate
11-form1_deactivate

Well, after clicking 'OK', The onclosing and onclosed operations are more complicated than clicking 'x.
__________I believe that through the above instructions, coupled with your own single-step debugging, you have understood the program loading and exit mechanisms.OK, that's it!Good luck!

--------------------------------------------------

Lee Sen-Listen
E-mail: lisencool@gmail.com

Statement:
Here we focus onWinCEAndWindows MobileSome basic knowledge in development. I would like to share with you, and I hope you will give your comments and contribute to me. I will post your name for you as soon as possible!

Announce:
Here collects general knowledge on WinCE and Windows Mobile. i'm very gglad to share them with all friends, and also hope you can share your problems and opinions and contribute articles to me to share with others. i'll publish your articles and sign your name at the first time.

 







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.