C#WinForm窗体事件执行次序
来源:互联网 发布:天音淘宝店铺 编辑:程序博客网 时间:2024/06/06 07:50
一、以下是网络上可搜索到的次序
当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件:
System.Windows.Forms.Control.HandleCreated
System.Windows.Forms.Control.BindingContextChanged
System.Windows.Forms.Form.Load
System.Windows.Forms.Control.VisibleChanged
System.Windows.Forms.Form.Activated
System.Windows.Forms.Form.Shown
当应用程序关闭时,会以下列顺序引发主要表单的关闭事件:
System.Windows.Forms.Form.Closing
System.Windows.Forms.Form.FormClosing
System.Windows.Forms.Form.Closed
System.Windows.Forms.Form.FormClosed
System.Windows.Forms.Form.Deactivate
二、以下是我测试的次序,全部protected override 这些事件,并且在其base.的前后分别处理一次,如下
- protected override void OnLoad(EventArgs e)
- {
- textBox1.Text += "OnLoad1" + "/r/n";
- base.OnLoad(e);
- textBox1.Text += "OnLoad2" + "/r/n";
- }
OnClientSizeChanged1
OnClientSizeChanged2
OnClientSizeChanged1
OnClientSizeChanged2
// Loyout要多次执行
OnLayout1
OnLayout2
OnHanleCreated1
OnHanleCreated2
OnInvalidated1
OnInvalidated2
// 注意这里的一点点变化
OnCreateControl1
OnLoad1
OnLoad2
OnCreateControl2
//
OnLayout1
OnLayout2
OnActivated1
OnActivated2
OnShown1
OnShown2
OnPain1
OnPain2
希望这个次序能给大家带来用处。。可以在不同事件中去处理所需要的代码
三、以下是代码源。C# 2008 Express
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- // using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- // 输出窗体事件的执行次序
- protected override void OnActivated(EventArgs e)
- {
- textBox1.Text += "OnActivated1" + "/r/n";
- base.OnActivated(e);
- textBox1.Text += "OnActivated2" + "/r/n";
- }
- protected override void OnClientSizeChanged(EventArgs e)
- {
- textBox1.Text += "OnClientSizeChanged1" + "/r/n";
- base.OnClientSizeChanged(e);
- textBox1.Text += "OnClientSizeChanged2" + "/r/n";
- }
- protected override void OnCreateControl()
- {
- textBox1.Text += "OnCreateControl1" + "/r/n";
- base.OnCreateControl();
- textBox1.Text += "OnCreateControl2" + "/r/n";
- }
- protected override void OnDeactivate(EventArgs e)
- {
- textBox1.Text += "OnDeactivate1" + "/r/n";
- base.OnDeactivate(e);
- textBox1.Text += "OnDeactivate2" + "/r/n";
- }
- protected override void OnHandleCreated(EventArgs e)
- {
- textBox1.Text += "OnHanleCreated1" + "/r/n";
- base.OnHandleCreated(e);
- textBox1.Text += "OnHanleCreated2" + "/r/n";
- }
- protected override void OnHandleDestroyed(EventArgs e)
- {
- textBox1.Text += "OnHanleDestoryed1" + "/r/n";
- base.OnHandleDestroyed(e);
- textBox1.Text += "OnHanleDestoryed2" + "/r/n";
- }
- protected override void OnInvalidated(InvalidateEventArgs e)
- {
- textBox1.Text += "OnInvalidated1" + "/r/n";
- base.OnInvalidated(e);
- textBox1.Text += "OnInvalidated2" + "/r/n";
- }
- protected override void OnLayout(LayoutEventArgs levent)
- {
- textBox1.Text += "OnLayout1" + "/r/n";
- base.OnLayout(levent);
- textBox1.Text += "OnLayout2" + "/r/n";
- }
- protected override void OnLoad(EventArgs e)
- {
- textBox1.Text += "OnLoad1" + "/r/n";
- base.OnLoad(e);
- textBox1.Text += "OnLoad2" + "/r/n";
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- textBox1.Text += "OnPain1" + "/r/n";
- base.OnPaint(e);
- textBox1.Text += "OnPain2" + "/r/n";
- }
- protected override void OnShown(EventArgs e)
- {
- textBox1.Text += "OnShown1" + "/r/n";
- base.OnShown(e);
- textBox1.Text += "OnShown2" + "/r/n";
- }
- }
- }
- C#WinForm窗体事件执行次序
- [转]C#WinForm窗体事件执行次序
- C#WinForm窗体事件执行次序
- C#WinForm窗体事件执行次序(较完整版)
- C#WinForm窗体事件执行次序-启动、退出
- C#中WinForm窗体事件的执行次序
- C#中WinForm窗体事件的执行次序如下:
- WinForm载入窗体完成后自动执行事件
- Page里的事件 执行的次序
- winform窗体失去焦点事件
- c# winform窗体关闭事件
- [zz]winform 窗体关闭事件
- winform子窗体加载父窗体事件
- 带有按钮并且可以执行单击事件的WINFORM窗体,体悟C#的创建过程
- C#-winform-设计登录窗体
- (C#)WinForm窗体间传值
- (C#)WinForm窗体间传值
- (C#)WinForm窗体间传值
- Java 多线程讲解
- XML有关键字无法识别怎么办?
- 百度2014校园招聘笔试题
- C++并发实战6:thread::id
- 打印DATAgridview所见即所得
- C#WinForm窗体事件执行次序
- Linux DHCP & DNS
- eclipse上hdfs的javaapi调用文件或者获取节点信息没有权限
- QT中QMessageBox设计选择框
- AndroidAnnotations——Enhancing the Application class优化Application类
- 面试知识点总结之c++基础(二)
- 强大的vim配置文件,让编程更随意
- IOS成长之路-JSON解析
- jquery对象与js对象的相互转换