2010-02-16 6 views

Répondre

6

Bien sûr, vous pouvez!

Dans vos propriétés de projet, définissez Objet de démarrage sur Sub Main et assurez-vous qu'il existe une méthode Public Sub Main quelque part dans votre application. Une classe de démarrage séparée peut être une bonne idée:

Public Class myStartupClass

''' <summary> 
''' This is the method that will be run when the application loads, 
''' because Project Properties, Startup Object is set to SubMain 
''' </summary> 
''' <remarks> 
''' </remarks> 
''' -------------------------------------------------------------------------------- 
Public Shared Sub Main() 

    'The form that we will end up showing 
    Dim formToShow As System.Windows.Forms.Form = Nothing 

    'The determiner as to which form to show 
    Dim myMood As String = "Happy" 

    'Choose the appropriate form 
    Select Case myMood 
     Case "Happy" 
      formToShow = New Form1 
     Case Else 
      formToShow = New Form2 
    End Select 

    'Show the form, and keep it open until it's explicitly closed. 
    formToShow.ShowDialog() 

End Sub 

End Class

+0

incroyable! Je vous remercie! –

4

Dans une "application Windows Forms", créée sous VB 2010 Express, vous pouvez effectuer les opérations suivantes dans ApplicationEvents.vb :

Partial Friend Class MyApplication 

    Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup 

     'Select the form of your choice 
     My.Application.MainForm = Any_Form_You_like 

    End Sub 

End Class 
0

C'est l'approche que j'utilise qui démarre effectivement une forme comme un point d'entrée d'application normal.

Public Sub Main() 
    Dim value As String = Trim(Environment.CommandLine) 
    Dim f As Form 
    Select Case value 
     Case "a" 
      f = New frmTextEdit 
     Case "b" 
      f = New frmListDialog 
     Case "c" 
      f = New frmSuggestion 
     Case Else 
      Throw New Exception("Unsupported startup form option") 
    End Select 
    Application.Run(f) 
End Sub 
Questions connexes