本文介绍了显示表单时如何运行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 Load 事件可能会有所帮助,但以下代码只是立即显示完成".

I thought the Load event might help, but the following code just shows "Done" immediately.

public Form1()
{
    InitializeComponent();
    Load += new EventHandler(Form1_Load);
}

void Form1_Load(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(3000);
    Text = "Done";
}

如何在表单显示后让它休眠?

How do I make it Sleep after the form is shown?

谢谢.

推荐答案

Windows 窗体有一个 Shown 事件.查看:http://msdn.microsoft.com/en-us/library/system.windows.forms.form.shown.aspx

There is a Shown event for a windows form. Check out: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.shown.aspx

或者,如果你很懒惰,那就来吧:

Or if you are lazy, here you go:

public Form1()
{
    InitializeComponent();
    Shown += Form1_Shown;
}

private void Form1_Shown(object sender, EventArgs e) 
{
    System.Threading.Thread.Sleep(3000);
    Text = "Done";
}

享受.

这篇关于显示表单时如何运行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:46