开发者

Is there "LoadComplete" such an event in Windows Forms?

I want my windows form to be loaded first, render its children and all. After that load heavy data in it. This is why I am looking for any event which I could use just after form loading is complete.

Any though开发者_如何学JAVAts on this?


I have never found a better solution than Activated; although that is raised every time the form receives focus - so you need to filter out all the times after the first:

bool _firstActivation = true;
void Form1_Activated(object sender, EventArgs e)
{
    if (_firstActivation)
    {
        _firstActivation = false;
        OnFirstActivation();
    }
}

private void OnFirstActivation()
{

}


Perhaps you're looking for the Form.Shown event. If you're doing a lot of intensive work though, perhaps you should be using a background thread anyway to avoid locking up the UI.


Like MikeP said you want to handle the Form.Shown event just once. So just attach to the even and detach once done.

    private void frmMain_Load(object sender, System.EventArgs e)
    {
        // Do stuff in form load.

        Shown += FirstShown;
    }

    private void FirstShown(object sender, EventArgs eventArgs)
    {
        Refresh();

        // Do something here

        // Detach from this event.
        Shown -= FirstShown;
    }


I do that in a way that I fire a timer with duration of 1, and kill it in the event, and with that method, I know that message loop will be empty and form initialization will be complete when my event comes.

Event is set up from Form_OnLoad() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜