I have a Winforms Application with a TabStrip Control. During runtime, UserControls are to be loaded into different tabs dynamically.
I want to present a “User Control xyz is loading” message to the user (setting an existing label to visible and changing its text) before the UserControl is loaded and until the loading is completely finished.
My approaches so far:
- Trying to load the User Control in a BackgroundWorker thread. This fails, because I have to access Gui-Controls during the load of the UserControl
- Trying to show the message in a BackgroundWorker thread. This obviously fails because the BackgroundWorker thread is not the UI thread 😉
- Show the Message, call DoEvents(), load the UserControl. This leads to different behaviour (flickering, …) everytime I load a UserControl, and I can not control when and how to set it to invisible again.
To sum it up, I have two questions:
- How to ensure the message is visible directly, before loading the User control
- How to ensure the message is set to invisible again, just in the moment the UserControl is completely loaded (including all DataBindings, grid formattings, etc.)
what we use is similar to this:
within the method you use to start the thread set its properties to topmost true to ensure it stays on top.
for instance do this in your main form:
in the loading form class;