繁体   English   中英

Windows窗体显示隐藏控件无法正常工作

[英]Windows form show hide control not working as expacted

我有我的代码和问题如下

step1.Visible = true; 
//step1 is visible if i retrun from here but if do some work like below than its not visible until the task is completed
Thread.Sleep(5000); // some opration here  Thread.Sleep is just for example
step1.Visible = true;// step1 visible here not before thread going to sleep

在这里,我想显示每个步骤的图像,但是第一步图像没有显示它是否跟随一些长时间运行的任务在Thread.Sleep(5000)的情况下是否有任何想法/技巧show step1?

在睡眠(任何长时间运行)代码之前使用Application.DoEvents() Application.DoEvents()将处理当前在消息队列中的所有Windows消息。

step1.Visible = true; 

// Below 3 lines are not necessary. Use it only if DoEvents() doesn't work.
//step1.Invalidate();
//step1.Update();
//step1.Refresh();

// Will process the pending request of step1.Visible=true;
Application.DoEvents();

Thread.Sleep(5000);
step1.Visible = true;

我不确定我是否理解你想做什么,但首先我将使用这两个函数: Show()Hide()

现在你必须使用线程之间的多线程和通信

希望这可以帮助

您应该使用委托或后台工作程序来实现这一目标。 你可以从下面的链接获得和想法。

执行长进程时Windows窗体中的动画GIF

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM