gkket 发表于 2021-9-12 16:18:38

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

using System;
using System.Windows.Forms;

namespace WindowsFormsApp12
{
    /*
      1
      13
      14
      5
      6
      5
      6
      2
      7
      11
      12
      8
      9
      10
      3
      4
      15
      16
   */
    public partial class Form1 : Form
    {
      public Form1()
      {
            Console.WriteLine("1");
            InitializeComponent();
            Console.WriteLine("2");
      }
      protected override void OnActivated(EventArgs e)
      {
            Console.WriteLine("3");
            base.OnActivated(e);
            Console.WriteLine("4");
      }
      protected override void OnClientSizeChanged(EventArgs e)
      {
            Console.WriteLine("5");
            base.OnClientSizeChanged(e);
            Console.WriteLine("6");
      }
      protected override void OnCreateControl()
      {
            Console.WriteLine("7");
            base.OnCreateControl();
            Console.WriteLine("8");
      }
      protected override void OnGotFocus(EventArgs e)
      {
            Console.WriteLine("9");
            base.OnGotFocus(e);
            Console.WriteLine("10");
      }
      protected override void OnLoad(EventArgs e)
      {
            Console.WriteLine("11");
            base.OnLoad(e);
            Console.WriteLine("12");
      }
      protected override void OnResize(EventArgs e)
      {
            Console.WriteLine("13");
            base.OnResize(e);
            Console.WriteLine("14");
      }
      protected override void OnShown(EventArgs e)
      {
            Console.WriteLine("15");
            base.OnShown(e);
            Console.WriteLine("16");
      }
    }
}


言与午 发表于 2021-9-12 16:53:25

党的好公民,人民的好公仆。。。

董晶文 发表于 2021-9-14 02:21:03

强烈支持楼主ing……

BelieveDream 发表于 2025-11-14 13:06:30

原来还有这种操作,长见识了!

淡然 发表于 2025-11-14 13:19:39

同款经历!简直是世另我

521mimi 发表于 2025-11-14 14:57:53

救命!这回复笑到我捶桌,必须置顶~

yongyuan888518 发表于 2025-11-14 15:51:54

路过打卡,为优质内容疯狂打 call

koielee 发表于 2025-11-14 17:24:29

原来还有这种操作,长见识了!

藁卋朙 发表于 2025-11-14 23:41:57

理性围观,感觉大家说得都有道理

梁健文 发表于 2025-11-15 02:12:27

楼主太会说了,字字句句都在理~
页: [1] 2
查看完整版本: Winform 加载时各事件的顺序(一)