C#WinForm窗体事件执行次序(较完整版)
时间:2010-12-01 来源:林冠逹
OnClientSizeChanged1
OnClientSizeChanged2
OnClientSizeChanged1
OnClientSizeChanged2
// Loyout要多次执行
OnLayout1
OnLayout2
OnHanleCreated1
OnHanleCreated2
OnInvalidated1
OnInvalidated2
// 注意这里的一点点变化
OnCreateControl1
OnLoad1
OnLoad2
OnCreateControl2
//
OnLayout1
OnLayout2
OnActivated1
OnActivated2
OnShown1
OnShown2
OnPain1
OnPain2
希望这个次序能给大家带来用处。。可以在不同事件中去处理所需要的代码
三、以下是代码源
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
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";
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/neok/archive/2009/09/29/4616265.aspx
相关阅读 更多 +










