I read that the Load event should be fired after the window handle was created, but before the window really became visible. For the most part this seems true. However, I found that when I create a form with the WindowState property set to FormWindowState.Maximized (either through the VS constructor or programmatically in the constructor), the window becomes visible before the Load event Load . For example:
using System; using System.Windows.Forms; namespace MyApplication { public partial class MyForm : Form { public MyForm() { InitializeComponent(); WindowState = FormWindowState.Maximized; } protected override void OnLoad(EventArgs e) { MessageBox.Show("OnLoad - notice that the window is already visible"); base.OnLoad(e); } } }
This, in turn, causes the displayed form to flicker a lot, while its controls (which are laid out during the Form.Load event) change when the window is visible. If I did not set the maximum state, then all the resizing will be done before the window is shown (as I expected).
I could hold on to setting WindowState until the end of the Load event, but it still causes a lot of flickering because the window becomes visible and then all the controls change.
Any thoughts?
user1283610
source share