Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Mise à jour : novembre 2007
Cet exemple utilise l'événement My.Application.Startup pour vérifier si l'application a démarré avec la chaîne /batch comme argument.
Pour activer un mode batch pour une application Window Forms
Sélectionnez un projet dans l'Explorateur de solutions. Dans le menu Projet, cliquez sur Propriétés.
Dans l'onglet Application, cliquez sur Afficher les événements de l'application pour ouvrir l'éditeur de code.
Créez la méthode qui gère l'événement My.Application.Startup. Pour plus d'informations, consultez Comment : gérer les événements d'application (Visual Basic).
Private Sub MyApplication_Startup( _ ByVal sender As Object, _ ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs _ ) Handles Me.StartupEnd SubParcourez les arguments de ligne de commande de l'application, et affectez à la propriété Cancel de l'objet e la valeur True si l'un des arguments est /batch.
Lorsque la propriété Cancel a la valeur True, le formulaire de démarrage n'est pas lancé.
For Each s As String In My.Application.CommandLineArgs If s.ToLower = "/batch" Then ' Stop the start form from loading. e.Cancel = True End If NextSi la propriété Cancel de l'objet e a la valeur True, appelez la routine principale pour une opération sans fenêtre.
If e.Cancel Then ' Call the main routine for windowless operation. Dim c As New BatchApplication c.Main() End If
Exemple
Private Sub MyApplication_Startup( _
ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs _
) Handles Me.Startup
For Each s As String In My.Application.CommandLineArgs
If s.ToLower = "/batch" Then
' Stop the start form from loading.
e.Cancel = True
End If
Next
If e.Cancel Then
' Call the main routine for windowless operation.
Dim c As New BatchApplication
c.Main()
End If
End Sub
Class BatchApplication
Sub Main()
' Insert code to run without a graphical user interface.
End Sub
End Class
Voir aussi
Tâches
Comment : accéder aux arguments de ligne de commande (Visual Basic)
Concepts
Vue d'ensemble du modèle d'application Visual Basic