Solved

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

Posted on 2010-08-26
13
480 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
  • 6
  • 4
  • 3
13 Comments
 
LVL 85

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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 85

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 85

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now