Toggling Picture Box visibility C#

前端 未结 4 1356
失恋的感觉
失恋的感觉 2021-01-27 06:56

Why is the picture box control\'s visibility property not working here. I have initially set them to false, so that when the screen loads they are not visible. But then I wish t

相关标签:
4条回答
  • 2021-01-27 07:29

    Setting the Visible property to true doesn't show the control, it only creates a message that will show it. As long as you are keeping the main thread busy with a Sleep, it will not process any messages, and the controls won't be shown.

    You should show the picture boxes and then set up a timer with code that will hide the picture boxes when the timer's tick event is triggered. Then you exit your method so that the main thread can handle the messages that will show the picture boxes.

    0 讨论(0)
  • 2021-01-27 07:37

    Whenever the UI changes does not apear after you did some changes, always do Refres(). e.g. pictureBoxLeft.Refresh();. This will always make UI changes appear. Please let me know if it works for you.

    0 讨论(0)
  • 2021-01-27 07:42

    In addition to Thread.Sleep(); call Application.DoEvents() to trigger event handling/ui updating. However ensure you're not calling Action() again somehow. A simple Thread.Sleep() won't allow the UI to update as you're still in the handler and the framework won't be able fire any new events on its own as it won't know if you're finished when waiting (due to the thread still being busy).

    Overall your approach might be a bad idea (depending on other code etc.). Consider using timers or a background worker instead.

    0 讨论(0)
  • 2021-01-27 07:46

    This is your UI thread. UI thread is so busy that it is not getting time to refresh the display. UI thread is busy in endless while loop, so how can it update UI?

    0 讨论(0)
提交回复
热议问题