C#Form和Load和Shown

简介:     C#Form和Load和Shown这两个玩意容易混淆不?     案例测试一下: using System; using System.

    C#Form和Load和Shown这两个玩意容易混淆不?

    案例测试一下:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LoadShown
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private string[] mMessage = new string[] { "首先调用","第二调用"};
  18.         private int mIndex = 0;
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             MessageBox.Show("Form1_Load" + mMessage[mIndex++]);
  22.         }
  23.         private void Form1_Shown(object sender, EventArgs e)
  24.         {
  25.             MessageBox.Show("Form1_Shown" + mMessage[mIndex++]);
  26.         }
  27.     }
  28. }

image

image

Form.Load 事件

    在第一次显示窗体发生。注意这里有一个前字。明显它的触发要比Shown中的早。

Form.Shown 事件

    只有在首次显示窗体时才会引发 Shown 事件;随后执行的最小化、最大化、还原、隐藏、显示或无效化和重新绘制操作都不会引发该事件。

    C#Form和Load和Shown从此不再混淆。

参考文献:

https://msdn.microsoft.com/zh-cn/library/system.windows.forms.form.load(v=vs.110).aspx

https://msdn.microsoft.com/zh-cn/library/system.windows.forms.form.shown.aspx

http://bbs.csdn.net/topics/390149457

相关文章
|
3月前
|
前端开发
前端使用 <el-descriptions>标签报错: <el-descriptions> - did you register the component correctly
前端使用 <el-descriptions>标签报错: <el-descriptions> - did you register the component correctly
182 0
|
数据可视化 数据挖掘 开发者
Data-Basic Statistical Descriptions of Data| 学习笔记
快速学习 Data-Basic Statistical Descriptions of Data。
139 0
Data-Basic Statistical Descriptions of Data| 学习笔记
A small tip to explore how to call a method of a control
Created by Jerry Wang, last modified on Mar 20, 2015
128 0
A small tip to explore how to call a method of a control
|
JavaScript 前端开发
sendData to ABAP backend via multiple form content type
Created by Jerry Wang, last modified on Aug 20, 2014
105 0
sendData to ABAP backend via multiple form content type
How is target My note application rendered - renderManager
Created by Wang, Jerry, last modified on May 18, 2015
116 0
How is target My note application rendered - renderManager
Why manually change will not trigger text determination case 2
Why manually change will not trigger text determination case 2
106 0
Why manually change will not trigger text determination case 2
Why manually change will not trigger text determination
Why manually change will not trigger text determination
Why manually change will not trigger text determination
Performance problem during saving - activating big form
Performance problem during saving - activating big form