| |
23.3.10.Form life time event: Closing, Load, Closed, Activated, Deactivate |
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class FormLifeTimeEvent : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public FormLifeTimeEvent()
{
InitializeComponent();
this.Closing += new System.ComponentModel.CancelEventHandler(this.FormLifeTimeEvent_Closing);
this.Load += new System.EventHandler(this.FormLifeTimeEvent_Load);
this.Closed += new System.EventHandler(this.FormLifeTimeEvent_Closed);
this.Activated += new System.EventHandler(this.FormLifeTimeEvent_Activated);
this.Deactivate += new System.EventHandler(this.FormLifeTimeEvent_Deactivate);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(280, 177);
}
[STAThread]
static void Main()
{
Application.Run(new FormLifeTimeEvent());
}
private void FormLifeTimeEvent_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Console.WriteLine("Closing event");
}
private void FormLifeTimeEvent_Load(object sender, System.EventArgs e) {
Console.WriteLine("Load event");
}
private void FormLifeTimeEvent_Activated(object sender, System.EventArgs e) {
Console.WriteLine("Activate event");
}
private void FormLifeTimeEvent_Deactivate(object sender, System.EventArgs e) {
Console.WriteLine("Deactivate event");
}
private void FormLifeTimeEvent_Closed(object sender, System.EventArgs e) {
Console.WriteLine("Closed event");
}
}
|
|
|