2010-02-16 5 views

답변

6

물론 가능합니다.

프로젝트 속성에서 시작 개체를 Sub Main으로 설정하고 응용 프로그램의 어딘가에 Public Sub Main 메서드가 있는지 확인하십시오. 별도의 시작 클래스 좋은 생각이있을 수 있습니다 : VB 2010 익스프레스에서 만든 "윈도우 폼 응용 프로그램"에서

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

, 당신은 때 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 
관련 문제