How to create Wait Dialog : "Loading Data.Please Wait"

ntdong

New member
Joined
Jun 7, 2007
Messages
3
Programming Experience
Beginner
Hello all.
My Startup form open very slow. How can I show a wait screen while Initialize Component. Then close this wait screen and show my Form.
You can see my attached image.
 

Attachments

  • Loading Data.JPG
    Loading Data.JPG
    54.6 KB · Views: 232
It's not splash screen. Wait form could be a simple form that shows a message or as in most cases can be running some form of progress animation while the process is running.
 

Attachments

  • image1.JPG
    image1.JPG
    19.1 KB · Views: 174
  • image2.JPG
    image2.JPG
    33.7 KB · Views: 163
You say that you want to display another form containing a message while your startup form loads. What is that if not a splash screen? If you didn't want it specifically for your startup form then you shouldn't have said you did.

You should either:

1. load your data in a background thread while displaying the message in the UI thread; or
2. show the message in a background thread while loading your data in the UI thread.

The first option is preferable but the second may be required in certain circumstances. Check out the BackgroundWorker component.
 
but what if the loading process need to load data into certain control on the form? then it will cause cross-thread visit, right? or in this case i should use the second way u provided?
 
I do wish people would clearly state their situation so we can be sure that we're giving relevant advice. Is this message to be shown just before your startup form as you originally stated, or is it to be shown at some other time or times during the execution of your app as you have implied but never actually stated. We only know what you tell us so please be clear about what you're doing and what you want.
 
Actually, never mind. I found a really elegant way if you use DevExpress controls for winforms... the 2009 version 1.5

there is a undocumented tool that can be used. make a module with this code and it opens up a wait dialog box with status that can be updated as you go and runs on it's own thread, not the UI thread

so you just show it when u want and close it when u want it gone.

here is the code if you use devexpress controls for winforms




VB.NET:
Module ModuleWaitDialog
    Private Dlg As DevExpress.Utils.WaitDialogForm = Nothing
    Public Sub CreateWaitDialog(Optional ByVal Caption As String = "", Optional ByVal Title As String = "")
        If Title = "" Then
            Dlg = New DevExpress.Utils.WaitDialogForm(Caption)
        Else
            Dlg = New DevExpress.Utils.WaitDialogForm(Caption, Title)
        End If
    End Sub
    Public Sub CloseWaitDialog()
        Dlg.Close()
    End Sub
    Public Sub SetWaitDialogCaption(ByVal fCaption As String)
        If Dlg IsNot Nothing Then
            Dlg.Caption = fCaption
        End If
    End Sub
End Module
 
Back
Top