كيفية القيام بما يلي: تمكين الوضع الدفعي لتطبيقات Windows Forms

يستخدم هذا المثال حدث My.Application.Startup للتحقق من حالة تشغيل التطبيق مع السلسلة كوسيطة /batch .

لتمكين الوضع الدفعي لتطبيقات Windows Forms

  1. اختر المشروع المحدد في مستكشف الحلول. في قائمة مشروع, انقر فوق خصائص.

  2. في علامة التبويب التطبيق ، انقر فوق عرض أحداث التطبيق لفتح التعليمات البرمجية.

  3. إنشاء أسلوب لمعالجة حدث Startup. لمزيد من المعلومات، راجع كيفية القيام بما يلي: معالجة أحداث التطبيق (Visual Basic).

    Private Sub MyApplication_Startup( 
        ByVal sender As Object, 
        ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs 
    ) Handles Me.Startup
    
    End Sub
    
  4. كرر خلال وسيطات خط الأمر الخاصة بالتطبيق ، و عين خاصية Cancel لكائن e إلى True إذا كانت إحدى الوسائط /batch.

    عند تعيين خاصية Cancel إلى True، لا يتم تشغيل نموذج بدء التشغيل.

    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
    
  5. إذا كانت خاصية Cancel لكائن e معينة إلى True، استدعي الروتين الرئيسي للعملية بدون إطار.

    If e.Cancel Then
        ' Call the main routine for windowless operation.
        Dim c As New BatchApplication
        c.Main()
    End If
    

مثال

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

راجع أيضًا:

المهام

كيفية القيام بما يلي: الوصول إلى وسيطات خط الأوامر (Visual Basic)

المرجع

ApplicationBase

CommandLineArgs

المبادئ

نظرة عامة حول نموذج تطبيق Visual Basic