2010-02-16 180 views

回答

6

當然可以!

在您的項目屬性中,將Startup Object設置爲Sub Main,並確保應用程序中某處存在Public Sub Main方法。一個單獨的啓動類可以是一個好主意:

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

太棒了!謝謝! –

4

在 「Windows窗體應用程序」,在VB 2010 Express創建,你可以做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

這是我使用的方法,它有效地啓動一個窗體就像一個正常的應用程序入口點。

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 
相關問題