1

I have a form that takes a bit to load (needs to fetch some values from the database).

So I made a simple "please wait" splash screen, show it before intancing the form, close it and show the form:

Dim sp As New SplashScreen2
sp.Show()
Dim a = New AsignarFormacionesUsuario(p)
a.Text = "Asignar formaciones a: " + p.NomComplet
a.Show()
sp.Close()

The problem is that the splash screen does not loas the controls correctly:

How its seen

It should be:

How it should be

If I remove the intancing and showing of my form (and the closing of the splash so it does not instantly close) it's shown perfectly.

So it seems to not be a problem of the splash but a that the instancing of the form dont let the splash load correctly.

I don't know what to try, It seems that i just need the instancing to wait for the splash Show() to finish. But shouldn't it wait already?

Community
  • 1
  • 1
Aimnox
  • 895
  • 7
  • 20
  • When the UI thread is blocked the UI won't update. You need to give the UI thread time to update after you show your splash. – Thorsten Dittmar Jun 23 '16 at 10:44
  • @ThorstenDittmar, GuidoG's answer made it show the controls, but the gif does not move. I do need another thread for it to work, right? – Aimnox Jun 23 '16 at 10:50
  • 1
    I'd guess so. That said, have you checked for ready-made components out there that do splash screens? They might already have such features... – Thorsten Dittmar Jun 23 '16 at 10:53

1 Answers1

2
Dim sp As New SplashScreen2  
sp.Show()  

sp.Update() 

Dim a = New AsignarFormacionesUsuario(p)
SysDragon
  • 9,692
  • 15
  • 60
  • 89
GuidoG
  • 11,359
  • 6
  • 44
  • 79
  • It does show it now, but the "loading" gif does not move. Do I need to use another thread so it can amnage both, the load and the gif? – Aimnox Jun 23 '16 at 10:47
  • what control are u using to display the gif ? Have you checked if the gif moves when u view it directly in windows image preview ? – GuidoG Jun 23 '16 at 10:49
  • A pictureBox. The gif does move when I dont instance the `AsignarFormacionesUsuario` form, but not in Windows nor the form designer – Aimnox Jun 23 '16 at 10:52
  • sounds like a thread issue, you could try to do Application.DoEvents() in stead of sp.Update() but I am afraid you need to create another thread to make the gif move because your second form is blocking the ui thread of sp – GuidoG Jun 23 '16 at 10:55
  • 1
    http://stackoverflow.com/questions/1918158/how-do-i-show-a-loading-please-wait-message-in-winforms-for-a-long-loadi – GuidoG Jun 23 '16 at 10:58
  • 1
    this one may be better : http://stackoverflow.com/questions/31315793/how-to-show-an-animated-loading-form-while-executing-code-in-windows-forms-c-sha – GuidoG Jun 23 '16 at 10:59