views:

89

answers:

2

Hi Folks

I am trying to use a Main () function in a class to control the program flow in my vb .net Windows Forms application. I have added a splash screen component and a login screen, and customised my main sdi form. I have set the startup form to be my main function in the Application Page of the Project Designer, and everything seems to work fine(ish).

However, I would like to use: Me.MinimumSplashScreenDisplayTime = 5000

to ensure that the splash screen is visible, but it is not recognised by the system unless I tick the Enable Application Framework check box on the Project Designer. If I do this, on startup the program ignores the login and splash screens and all my customisation and just displays a default Form1, even though I have also specified my splash screen in the AF dropdown list.

Of course, there are alternative ways to delay a splash screen, such as putting the thread temporarily to sleep (which didn't seem to work), but I suspect that there are other things in the AF that I may want to use.

Any suggestions on how I can get round this please, and get a sensible means of controlling program flow? Any thoughts on the best overall structure for organising program flow would also be helpful too. I am concerned both about going down a Microsoft or an alternative custom route that may cause me problems later, as the application becomes more complex.

Thanks.

* Update *

Hi again. I have tried both answers, and incorporated this one from Hans Passant into my code, and eventually resolved all the error messages. However, it hasn't fixed the problem, as my splash screen does not stay open for 5 secs. It appears that the MS splash screen and minimum display time code can only be accessed if the Application Framework is being used, and I'm trying to produce my own custom startup, as I want to begin with a module/class function, rather than a form. Any (more) ideas? Thanks.

+1  A: 

Try this:

Protected Overrides Function OnInitialize( _
    ByVal commandLineArgs As _
    System.Collections.ObjectModel.ReadOnlyCollection(Of String) _
) As Boolean
    ''# Set the display time to 5000 milliseconds (5 seconds). 
    Me.MinimumSplashScreenDisplayTime = 5000
    Return MyBase.OnInitialize(commandLineArgs)
End Function

This was taken off the MSDN Site.

Codex73
+1  A: 

You should be able to do what you want to do in Sub Main() with the Startup event. Project + Properties, Application tab, scroll down, click View Application Events. Upper left combo, select "(My Application Events)". Upper right combo, select Startup.

Nevertheless, you can still get the application framework and start it through Sub Main(). Add a module to your project and make it look like this:

Imports Microsoft.VisualBasic.ApplicationServices

Module Module1
  Sub Main(ByVal args() As String)
    Dim app As New MyApp
    app.Run(args)
  End Sub
End Module

Class MyApp
  Inherits WindowsFormsApplicationBase
  Public Sub New()
    Me.SplashScreen = New SplashScreen1()
    Me.MinimumSplashScreenDisplayTime = 5000
  End Sub
  Protected Overrides Sub OnCreateMainForm()
    Me.MainForm = New Form1()
  End Sub
End Class
Hans Passant