Solved

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

Posted on 2010-08-26
13
486 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
Independent Software Vendors: 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

628 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