簡體   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