问题描述
我读了加载
事件是应该的窗口句柄创建之后被解雇,但是的在的窗口实际上变得可见。在大多数情况下,这似乎是正确的。不过,我发现,当我创建了的WindowState
属性设置为 FormWindowState.Maximized
形式(通过在VS设计,编程或在构造函数中),窗口变得可见的加载之前
事件射击。例如:
I read that the Load
event is supposed to be fired after the window handle has been created, but before the window actually become visible. For the most part, this seems to be true. However, I've found that when I create a form with the WindowState
property set to FormWindowState.Maximized
(either via the VS designer, or programatically in the constructor), the window becomes visible prior to the Load
event firing. 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);
}
}
}
这反过来又导致显示的形式来忽悠了不少,而它的控制(其中 Form.Load
活动期间都摆出来)的大小,而窗口可见。如果我没有设置状态得到最大限度的发挥,那么所有的大小调整完成的窗口显示前(这是我本来期望)。
This in turn causes the displayed form to flicker a lot while its controls (which are laid out during the Form.Load
event) are resized while the window is visible. If I did not set the state to be maximized, then all the resizing is done before the window is shown (which is what I would have expected).
我可以暂缓设置的WindowState
,直到加载
事件的结束,但仍然引起很多闪烁的,因为窗口变得可见,然后所有的控件的调整。
I could hold off on setting the WindowState
until the end of the Load
event, but that still causes a lot of flickering because the window becomes visible and then all of the controls resize.
有什么想法?
推荐答案
尽量拖延的WindowState的变化,直到第一个激活的事件触发。这对我的作品在VB.NET与VS2005和框架2.0。
Try to delay the change of WindowState until the first Activated event firing. This works for me in VB.NET with VS2005 and framework 2.0.
这篇关于设置的WindowState为最大化导致窗口出现得太早的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!