Solved

How can I close a splash screen during the main form's Load event?

Posted on 2010-08-26
13
484 Views
Last Modified: 2013-12-26
I have an application that performs a series of tests during the main form Load event. I want to display error messages when a test fails, but the problem I am having is that the splash screen is rendered on top of the message box, and I cant close the splash screen because I dont have access to the splash screen object (I think windows creates it in a different threat).
Is there anything I can do to allow me to close the splash screen before the main form is finished loading? Alternativaly, is there anything I can do to render messageboxes on top of the splash screen?
0
Comment
Question by:aferia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33535480
What version VB.net and how are you displaying the splash screen?
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33535487
Search your code for frmSplash.Show or whatever the splash form's name is. It's either in your main form's Load event or sub Main(). Before the messagebox opens up, do a close on the splash screen.

        SplashScreen1.Show()
        ' testing code here
         SplashScreen1.Close()
         MessageBox.Show("message here")
 

0
 

Author Comment

by:aferia
ID: 33535762
I am running VS 2005 and I have added the splash screen by selecting a form  through the properties window for the project.
Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Zhaolai
ID: 33535806
Then the splash form must have a name. You must have code to show the splash form,  Then you can close it at will.
 
0
 

Author Comment

by:aferia
ID: 33535822
I would like to keep the initialization code in the Main Form's Load event as I have a few member variables in Main that are used by the tests.
0
 

Author Comment

by:aferia
ID: 33535871
The splash screen has a name 'FSplashScreen', but if I try to close it from the Main's Load II get an error message because the splash screen object is declared in a different thread, so I cant have access to it.

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33535926
Maybe you don't need another thread for splash screen. Can it be in the same thread as the main form?
0
 

Author Comment

by:aferia
ID: 33536022
This is the behavior implemented by VS 2005, I have no control over it. It works well because it shows the splash screen before anything from my main form is loaded. Otherwise it would have a delay even if I showed it on the first line of code in Main's load.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33536026
Zhaolia...he said:

    "I have added the splash screen by selecting a form  through the properties window for the project."

So the Framework is displaying the splash screen by itself and managing the thread...

Attached is an image of what it would look like in Project --> Properties.

Below is one way to make the splash screen close itself from the main form:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug.Print("First Sleep")
        System.Threading.Thread.Sleep(3000)

        Debug.Print("Closing Splash Form...")

        FSplashScreen.CloseIt()

        Debug.Print("Second Sleep")
        System.Threading.Thread.Sleep(3000)
    End Sub

End Class

Public Class FSplashScreen

    Public Sub CloseIt()
        Me.Invoke(New Action(AddressOf CloseSplash))
    End Sub

    Private Sub CloseSplash()
        Me.Close()
    End Sub

End Class

Open in new window

SplashScreenSetting.jpg
0
 

Author Comment

by:aferia
ID: 33536201
The line: Me.Invoke(New Action(AddressOf CloseSplash)) is causing the following compile error:
Too few type arguments to 'System.Action(Of T)'
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33536236
*I'm running VS2010 so there are slight differences...

Try this instead:
Public Class FSplashScreen

    Public Delegate Sub CloseDelegate()

    Public Sub CloseIt()
        Me.Invoke(New CloseDelegate(AddressOf CloseSplash), New Object() {})
    End Sub

    Private Sub CloseSplash()
        Me.Close()
    End Sub

End Class

Open in new window

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33536275
@Idle_Mind, thanks. Learn something today.
0
 

Author Closing Comment

by:aferia
ID: 33536308
Awesome! This bug in my software had been lingering around for a long time! This got me interested in learning more about the Invoke method, I had never heard of it before. Thanks a lot for the help!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question