Winform 加载时各事件的顺序(二)

Winform 加载时各事件的顺序

using System;
using System.Windows.Forms;

namespace WindowsFormsApp13
{
    /*
        public Form1 before InitializeComponent
        OnResize before base.OnResize
        OnResize after base.OnResize
        OnClientSizeChanged before base.OnClientSizeChanged
        OnClientSizeChanged after base.OnClientSizeChanged
        OnClientSizeChanged before base.OnClientSizeChanged
        OnClientSizeChanged after base.OnClientSizeChanged
        public Form1 after InitializeComponent
        OnCreateControl before base.OnCreateControl
        OnLoad before base.OnLoad
        OnLoad after base.OnLoad
        OnCreateControl after base.OnCreateControl
        OnGotFocus before base.OnGotFocus
        OnGotFocus after base.OnGotFocus
        OnActivated before base.OnActivated
        OnActivated after base.OnActivated
        OnShown before base.OnShown
        OnShown after base.OnShown
     */
    public partial class Form1 : Form
    {
        public Form1()
        {
            Console.WriteLine("public Form1 before InitializeComponent");
            InitializeComponent();
            Console.WriteLine("public Form1 after InitializeComponent");
        }
        protected override void OnActivated(EventArgs e)
        {
            Console.WriteLine("OnActivated before base.OnActivated");
            base.OnActivated(e);
            Console.WriteLine("OnActivated after base.OnActivated");
        }
        protected override void OnClientSizeChanged(EventArgs e)
        {
            Console.WriteLine("OnClientSizeChanged before base.OnClientSizeChanged");
            base.OnClientSizeChanged(e);
            Console.WriteLine("OnClientSizeChanged after base.OnClientSizeChanged");
        }
        protected override void OnCreateControl()
        {
            Console.WriteLine("OnCreateControl before base.OnCreateControl");
            base.OnCreateControl();
            Console.WriteLine("OnCreateControl after base.OnCreateControl");
        }
        protected override void OnGotFocus(EventArgs e)
        {
            Console.WriteLine("OnGotFocus before base.OnGotFocus");
            base.OnGotFocus(e);
            Console.WriteLine("OnGotFocus after base.OnGotFocus");
        }
        protected override void OnLoad(EventArgs e)
        {
            Console.WriteLine("OnLoad before base.OnLoad");
            base.OnLoad(e);
            Console.WriteLine("OnLoad after base.OnLoad");
        }
        protected override void OnResize(EventArgs e)
        {
            Console.WriteLine("OnResize before base.OnResize");
            base.OnResize(e);
            Console.WriteLine("OnResize after base.OnResize");
        }
        protected override void OnShown(EventArgs e)
        {
            Console.WriteLine("OnShown before base.OnShown");
            base.OnShown(e);
            Console.WriteLine("OnShown after base.OnShown");
        }
    }
}


作者最新文章
Winform TextBox (文本框) 密码输入框, 输入内容显示*号 (星号)
Winform 启动前弹出登录界面, 登录成功之后再显示主界面
C# 字符串string和字符数组char[]的相互转换
C# 字符串倒序输出, 实现字符串倒序的方法
Winform 如何从 TextBox(文本框) 控件读取每一行数据到数组