In the process of learning the second chapter of GDI + Advanced programming, there is a question, that is why some code is used to overwrite an onload event, and on weekdays I use the General Form1_Load event, these two functions are very similar, but what is the specific relationship? A similar code looks like this:
OnLoad event: protected override void OnLoad (EventArgs e) {
Base. OnLoad (e); }
Form1_Load event: private void Form1_Load (object sender, EventArgs e) {
}
Later looked up the relevant information, reference website: http://blog.sina.com.cn/s/blog_963217380100zw8p.html
The reason for this discovery is this:
The onload function in the base class raises the event call Form1_Load. If you override the OnLoad function but do not call Base.onload (e), but define your own actions when the program loads, the code that raises the event in the base class will not be executed, that is, the Form1_Load will not be executed.
In this sense, it can be understood that the OnLoad event contains the Form1_Load event, or the OnLoad event before it touches the Form1_Load event. If you write some preprocessing ahead of Form_Load in the override onload event, the code will be loaded with the window first. Let's take a closer look at the specific invocation of the event, and see the sequence of events that the program starts in VS:
1-form1 Constructor
2-onload
3-form1_load
4-onactivated
5-form1_activated
From the above order we can know that the program starts in the order of "constructor-load-activated".
So it seems that not all onxxx events will happen before the xxx event? I found some information, it seems to be true, C # programming specifications, the occurrence of the XXX event will usually be written in onxxx implementation code, and can override onxxx to customize the control. Basically, the OnXxx event triggers the event before passing the argument to xxx to call Jiangzi.
Then you know the sequence of events initiated by the program, then look at the exit order after clicking the Close window,
1-form1 Constructor
2-onload
3-form1_load
4-onactivated
5-form1_activated
6-ondeactivate
7-form1_deactivate
Can get click to close the program after the first event is "Deactivate", but did not enter the onclosing and onclosed, so we also understand why the initial click ' X ' after the program does not quit the reason. So, what to do, it's very simple, because the program enters deactivate after the point ' X ', so we call This.close () in OnDeactivate or form1_deactivate will be able to enter into the onclosing and onclosed, and then in OnClosing and onclosed to do some exit processing, that is!
Finally, let's look at the exit order of the program after clicking ' OK ' in the prompt window of the OnClosing event:
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
Sure enough it was more onclosing and onclosed handled.
The difference between the OnLoad event and the Form1_Load event