Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-26
13
Medium Priority
?
492 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 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
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!

 
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 2000 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

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!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

971 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