表单不加载组件 [英] Form does not load components

查看:74
本文介绍了表单不加载组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,所以这似乎是一个愚蠢的问题.

我有一个登录表单,该表单调用其他表单,其中显示"..请等待加载".

在表格2中,我对此有一个标签.

现在的问题是,直到在login_click事件中执行了所有操作之后,该标签的文本才会出现.

例如:

I am a newbie, so it might seems a silly question.

I have a login form which calls other form where it says .. "please wait while it loads".

in form 2 i have a label for that.

Now the problem is that the text for that label doesnot appears until everything is executed in the login_click event.

Ex:

private void cmdLogin_Click(object sender, EventArgs e)
{
    frm2 objfrm = new frm2();
    frm2.show();

    // Manything to execute.
    
   frm2.close();
}



现在它加载了form2,但标签文本没有出现.

我删除了frm2.close()并知道从cmdLogin_Click函数中出来后,它就会显示文本.

我还尝试了frm2.showdialog(),该程序会加载文本,但代码在该行停止,并且不会移至cmdLogin_Click函数中的下一行.

有什么解决办法吗?

我们将不胜感激.



Now it loads form2 but the label text doesnot appears.

I removed frm2.close() and came to know that after it comes out of the cmdLogin_Click function, it the text appears.

I also tried frm2.showdialog(), which loads the text but the code stops at that line and doesnot move to next line in the function cmdLogin_Click.

Is there any solution for this?

Help would be appreciated.

推荐答案

有一个解决方案,但这并不简单:您需要将耗时的代码移出Click事件,并移至单独的线程.这并不坏,但是对于一个新手来说,它可能会引入许多您还没有学过并且不了解的概念.

有一个讨厌,快速和肮脏的解决方案"可以解决您的问题,但我可能会通过推荐它来使很多人烦恼-通常我会建议您避免使用它,但它比尝试向您介绍线程和UI/后台线程尤其如此.

如果必须显示该内容,则在您的时间密集型代码中,经常调用Application.DoEvents方法.如果有循环,请在循环的每次迭代结束时调用它.就像魔术一样,您的问题将消失……但其他问题可能还会发生!

为什么不以"objfrm"形式登录呢?
There is a solution, but it is not simple: you need to move the time intensive code out of your Click event, and into a separate thread. It''s not to bad, but for a newbie, it may introduce a lot of concepts you haven''t been taught yet, and don''t understand.

There is a nasty, quick and dirty "solution" which may solve your problem, but I will probably upset a lot of people by recommending it - normally I would suggest avoiding the use, but it seems safer than trying to introduce you to threading and UI / background threads in particular.

If you must have this display, then in your time intensive code, call the Application.DoEvents method often. If you have a loop, call it at the end of each iteration round the loop. Like magic, your problem will vanish...but others will probably occur!

Why not do the logging in in your "objfrm" form instead?


这篇关于表单不加载组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆