1

I am new to splash screen , however I am trying to load data onto datagrid from database and it takes around 30 sec so I was thinking to put a "Loading ....Please wait" splash screen with progress bar. I tried Jacques Bourgeois (James Burger)'s advice on this link> I tried

splashScreen.Show();
// Do your stuff - No need to start another thread. The form is visible on the screen, and since
// Show is asynchrone (not blocking), the code between the Show and the Close runs while the form is displayed.
splashScreen.Close();

I have used a picture box and a progress bar , the splash screen loads fine and closes fine but the splash screen is blank. I googled I saw use of background, I dont know how to use it so thought to use above simple code So what am I doing wrong here. However I have set property as

Show in taskbar = False

mark
  • 623
  • 3
  • 21
  • 54
  • Just open the Forms designer, add a PictureBox. Set it's Image property from Properties toolbar and anchor it to all four sides. Don't forget to right click on the PictureBox and choose "Send to Back" from the context menu to keep it floating over form controls (if there are any) – user3021830 Feb 13 '15 at 14:44
  • do you have some updates of the screen values? – Yuriy Zaletskyy Feb 13 '15 at 14:46
  • @user3021830 it didnt work. Its same – mark Feb 13 '15 at 14:58
  • Take a look at [Windows Forms Splash Screen](https://stackoverflow.com/a/32421479/3110834) or [Show a Loading animation during loading data](https://stackoverflow.com/a/39142535/3110834). – Reza Aghaei Dec 02 '19 at 05:39

1 Answers1

2

That happens because image wasn't loaded. I propose you to avoid picture box, and instead of PictureBox use BackgroundImage property at splash screen. I tested splash screen with the following code:

private void button1_Click(object sender, EventArgs e)
{
           splashScreen s = new splashScreen();
           s.Show();
           Thread.Sleep(5000);
           s.Close();
}
Yuriy Zaletskyy
  • 4,983
  • 5
  • 34
  • 54
  • Having `Thread.Sleep(5000);` will cause the UI thread to be blocked, which the OP did not want. – AWinkle Feb 13 '15 at 14:56
  • That is just for demonstrating how I tested splash screen. Instead of it can be method which reads data from db, as mentioned in question – Yuriy Zaletskyy Feb 13 '15 at 14:57
  • 1
    Thanks @YuraZaletskyy it worked fine however didn't try thread.spleep, changing to BackgroundImage worked fine. I also have progress bar which still is invisible. How to solve that – mark Feb 13 '15 at 15:03
  • 1
    Sadly to disappoint you, but you'll need second thread. You can't in one thread to load data and update GUI. – Yuriy Zaletskyy Feb 13 '15 at 15:17
  • @YuraZaletskyy will try however can you give me a link or tell me in a simple way how to achieve as I told I am new with threading concept. – mark Feb 14 '15 at 05:19
  • http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c and interesting idea here: http://www.codeproject.com/Articles/52752/Updating-Your-Form-from-Another-Thread-without-Cre – Yuriy Zaletskyy Feb 14 '15 at 11:16