Aracılığıyla paylaş


Nasıl yapılır: Program özel durum ileti kutusu

Özel durum ileti kutusu uygulamalarınızda ileti deneyimi üzerinde tarafından sağlanan göre önemli ölçüde daha fazla denetim sağlamak için kullanabileceğiniz MessageBox WalkTreeDaha fazla bilgi için bkz: Özel durum ileti kutusu programlama.Nasıl elde edilir ve özel durum iletisi kutusunu .dll dağıtmak hakkında daha fazla bilgi için bkz: Özel durum ileti kutusu uygulama dağıtma.

Yordam

Özel durum iletisi kutusunu kullanarak bir özel durum işleme

  1. Başvuru Microsoft.ExceptionMessageBox.dll için yönetilen kod projenizde ekleyin derleme.

  2. (İsteğe bağlı) Ekleme bir using (C#) veya Imports ()Microsoft Visual Basic.net) yönergesini kullanmak için Microsoft.SqlServer.MessageBox ad.

  3. Try-catch oluşturmak blok beklenen özel durumunu işlemesi için.

  4. İçinde catch engellemek, oluşturma bir örnek , ExceptionMessageBox WalkTreePASS Exception nesne tarafından ele try–catch blok.

  5. (İsteğe bağlı) Bir veya daha aşağıdaki özellikleri ayarlayın ExceptionMessageBox:

  6. Call Show yöntem.Özel durum iletisi kutusunu ait olduğu üst pencere geçişi.

  7. (İsteğe bağlı) Not değeri döndürülen DialogResult , kullanıcının hangi düğmesini belirlemeniz gerekiyorsa numaralandırma tıklattınız.

Bir özel durum olmadan özel durum ileti kutusu görüntülemek için

  1. Başvuru Microsoft.ExceptionMessageBox.dll için yönetilen kod projenizde ekleyin derleme.

  2. (İsteğe bağlı) Ekleme bir using (C#) veya Imports (Visual Basic.net) yönergesini kullanmak için Microsoft.SqlServer.MessageBox ad.

  3. Oluşturma bir örnek , ExceptionMessageBox WalkTreeİleti metni olarak geçmesi bir String değer.

  4. (İsteğe bağlı) Bir veya daha aşağıdaki özellikleri ayarlayın ExceptionMessageBox:

  5. Call Show yöntem.Özel durum iletisi kutusunu ait olduğu üst pencere geçişi.

  6. (İsteğe bağlı) Döndürülen değeri not DialogResult , kullanıcının hangi düğmesini belirlemeniz gerekiyorsa numaralandırma tıklattınız.

Özelleştirilmiş düğmeleri ile özel durum iletisi kutusunu görüntülemek için

  1. Başvuru Microsoft.ExceptionMessageBox.dll için yönetilen kod projenizde ekleyin derleme.

  2. (İsteğe bağlı) Ekleme bir using (C#) veya Imports (Visual Basic.net) yönergesini kullanmak için Microsoft.SqlServer.MessageBox ad.

  3. Oluşturma bir örnek , ExceptionMessageBox iki yoldan birini kullanarak sınıf:

    • PASS Exception nesne tarafından işlenen bir try–catch blok.

    • İleti metni olarak geçmesi bir String değer.

  4. Aşağıdaki değerleri için set Buttons:

    • AbortRetryIgnore-görüntüler İptal, yeniden, ve Yoksay düğmeleri.

    • Custom-Özel düğmeler görüntüler.

    • OK-görüntüler Tamam düğme.

    • OKCancel-görüntüler Tamam ve İptal düğmeleri.

    • RetryCancel-görüntüler yeniden ve İptal düğmeleri.

    • YesNo-görüntüler Evet ve No düğmeleri.

    • YesNoCancel-görüntüler Evet, No, ve İptal düğmeleri.

  5. (İsteğe bağlı) Özel düğmeler kullanırsanız, aşağıdakilerden aşırı çağrısı SetButtonText yöntem belirtmek için metin en çok beş özel düğmeler.

  6. Call Show yöntem.Özel durum iletisi kutusunu ait olduğu üst pencere geçişi.

  7. (İsteğe bağlı) Döndürülen değeri not DialogResult , kullanıcının hangi düğmesini belirlemeniz gerekiyorsa numaralandırma tıklattınız.Özel düğmeler kullanırsanız, değerini not ExceptionMessageBoxDialogResult için CustomDialogResult özellik olan özel kullanıcı düğmeleri belirlemek için tıklattığınız.

Özel durum iletisi kutusunu göstermek karar vermek kullanıcılara izin vermek için

  1. Başvuru Microsoft.ExceptionMessageBox.dll için yönetilen kod projenizde ekleyin derleme.

  2. (İsteğe bağlı) Ekleme bir using (C#) veya Imports (Visual Basic.net) yönergesini kullanmak için Microsoft.SqlServer.MessageBox ad.

  3. Oluşturma bir örnek , ExceptionMessageBox iki yoldan birini kullanarak sınıf:

    • PASS Exception nesne tarafından işlenen bir try–catch blok.

    • İleti metni olarak geçmesi bir String değer.

  4. Set the ShowCheckbox() özellik to true.

  5. (İsteğe bağlı) Özel durum ileti kutusu yeniden göstermek karar vermek için kullanıcı ister metin belirtmek CheckboxText()."Bu iletiyi yeniden gösterme." varsayılan metindir

  6. Uygulama yürütme süresi için yalnızca kullanıcının karar tutmanız gerekiyorsa küme değeri IsCheckboxChecked() bir genel Boolean değişkeni.Bu değer oluşturmadan önce değerlendirmek bir örnek özel durum ileti kutusunun.

  7. Bir kullanıcının karar kalıcı olarak depolamak istiyorsanız, aşağıdakileri yapın:

    1. Call CreateSubKey(String) , uygulamanızın kullandığı özel kayıt defteri anahtarını açma yöntem ve küme CheckboxRegistryKey() için döndürülen RegistryKey nesne.

    2. Set CheckboxRegistryValue() için kullanılan kayıt defteri değerinin adını.

    3. Set CheckboxRegistryMeansDoNotShowDialog() to true.

    4. Call Show yöntem.Belirtilen kayıt anahtar değerlendirilir ve yalnızca kayıt defteri anahtarında depolanan veri 0 özel durum ileti kutusu görüntülenir.İletişim kutusu görüntülenir ve kullanıcının bir düğmeyi tıklatmadan önce bu onay kutusunu işaretlerse, veri kayıt defteri anahtar 1 olarak küme.

Örnek

Özel durum ileti kutusu ile yalnızca bu örnek kullanır Tamam işlenmiş özel ek bilgilerle birlikte uygulamaya özgü içerir bir uygulama özel durum bilgilerini görüntülemek için düğmeyi.

          try
            {
                // Do something that may generate an exception.
                throw new ApplicationException("An error has occured");
            }
            catch (ApplicationException ex)
            {
                // Define a new top-level error message.
                string str = "The action failed.";

                // Add the new top-level message to the handled exception.
                ApplicationException exTop = new ApplicationException(str, ex);
                exTop.Source = this.Text;

                // Show an exception message box with an OK button (the default).
                ExceptionMessageBox box = new ExceptionMessageBox(exTop);
                box.Show(this);
            }
Try
    ' Do something that may generate an exception.
    Throw New ApplicationException("An error has occured")
Catch ex As ApplicationException
    ' Define a new top-level error message.
    Dim str As String = "The action failed."

    ' Add the new top-level message to the handled exception.
    Dim exTop As ApplicationException = New ApplicationException(str, ex)
    exTop.Source = Me.Text

    ' Show an exception message box with an OK button (the default).
    Dim box As ExceptionMessageBox = New ExceptionMessageBox(exTop)
    box.Show(Me)
End Try

Özel durum iletisi kutusunu bu örnek kullanır Evet ve No düğmeleri, kullanıcı seçer.

            // Define the message and caption to display.
            string str = @"Are you sure you want to delete file 'c:\somefile.txt'?";
            string caption = "Confirm File Deletion";

            // Show the exception message box with Yes and No buttons.
            ExceptionMessageBox box = new ExceptionMessageBox(str,
                caption, ExceptionMessageBoxButtons.YesNo,
                ExceptionMessageBoxSymbol.Question,
                ExceptionMessageBoxDefaultButton.Button2);

            if (DialogResult.Yes == box.Show(this))
            {
                // Delete the file.
            }
' Define the message and caption to display.
Dim str As String = "Are you sure you want to delete file 'c:\somefile.txt'?"
Dim caption As String = "Confirm File Deletion"

' Show the exception message box with Yes and No buttons.
Dim box As ExceptionMessageBox = New ExceptionMessageBox(str, _
 caption, ExceptionMessageBoxButtons.YesNo, _
 ExceptionMessageBoxSymbol.Question, _
 ExceptionMessageBoxDefaultButton.Button2)

If Windows.Forms.DialogResult.Yes = box.Show(Me) Then
    ' Delete the file.
End If

Bu örnek, özel düğmeler ile özel durum iletisi kutusunu kullanır.

            try
            {
                // Do something that may cause an exception.
                throw new ApplicationException("An error has occured");
            }
            catch (ApplicationException ex)
            {
                string str = "Action failed. What do you want to do?";
                ApplicationException exTop = new ApplicationException(str, ex);
                exTop.Source = this.Text;

                // Show the exception message box with three custom buttons.
                ExceptionMessageBox box = new ExceptionMessageBox(exTop);

                // Set the names of the three custom buttons.
                box.SetButtonText("Skip", "Retry", "Stop Processing");

                // Set the Retry button as the default.
                box.DefaultButton = ExceptionMessageBoxDefaultButton.Button2;
                box.Symbol = ExceptionMessageBoxSymbol.Question;
                box.Buttons = ExceptionMessageBoxButtons.Custom;

                box.Show(this);

                // Do something, depending on the button that the user clicks.
                switch (box.CustomDialogResult)
                {
                    case ExceptionMessageBoxDialogResult.Button1:
                        // Skip action
                        break;
                    case ExceptionMessageBoxDialogResult.Button2:
                        // Retry action
                        break;
                    case ExceptionMessageBoxDialogResult.Button3:
                        // Stop processing action
                        break;
                }
            }
Try
    ' Do something that may cause an exception.
    Throw New ApplicationException("An error has occured")
Catch ex As ApplicationException
    Dim str As String = "Action failed. What do you want to do?"
    Dim exTop As ApplicationException = New ApplicationException(str, ex)
    exTop.Source = Me.Text

    ' Show the exception message box with three custom buttons.
    Dim box As ExceptionMessageBox = New ExceptionMessageBox(exTop)

    ' Set the names of the three custom buttons.
    box.SetButtonText("Skip", "Retry", "Stop Processing")

    ' Set the Retry button as the default.
    box.DefaultButton = ExceptionMessageBoxDefaultButton.Button2
    box.Symbol = ExceptionMessageBoxSymbol.Question
    box.Buttons = ExceptionMessageBoxButtons.Custom

    box.Show(Me)

    ' Do something, depending on the button that the user clicks.
    Select Case box.CustomDialogResult
        Case ExceptionMessageBoxDialogResult.Button1
            ' Skip action
        Case ExceptionMessageBoxDialogResult.Button2
            ' Retry action
        Case ExceptionMessageBoxDialogResult.Button3
            ' Stop processing action
    End Select
End Try

Bu örnekte onay kutusunu özel durum ileti kutusunun gösterilip gösterilmeyeceğini belirlemek için kullanır.

          try
            {
                // Do something that may cause an exception.
                throw new ApplicationException("An error has occured.");
            }
            catch (ApplicationException ex)
            {
                string str = "The action failed.";
                ApplicationException exTop = new ApplicationException(str, ex);
                exTop.Source = this.Text;

                // Show a message box if the global variable is true.
                if (alwaysShow)
                {
                    ExceptionMessageBox box = new ExceptionMessageBox(exTop);
                    box.ShowCheckBox = true;
                    box.IsCheckBoxChecked = true;
                    box.CheckBoxText = "Always show this message";
                    box.Show(this);

                    // Set the global variable.
                    alwaysShow = box.IsCheckBoxChecked;
                }
            }
Try
    ' Do something that may cause an exception.
    Throw New ApplicationException("An error has occured.")
Catch ex As ApplicationException
    Dim str As String = "The action failed."
    Dim exTop As ApplicationException = New ApplicationException(str, ex)
    exTop.Source = Me.Text

    ' Show a message box if the global variable is true.
    If alwaysShow Then
        Dim box As ExceptionMessageBox = New ExceptionMessageBox(exTop)
        box.ShowCheckBox = True
        box.IsCheckBoxChecked = True
        box.CheckBoxText = "Always show this message"
        box.Show(Me)

        ' Set the global variable.
        alwaysShow = box.IsCheckBoxChecked
    End If
End Try

Bu örnek, özel durum ileti kutusunun gösterilip gösterilmeyeceğini belirlemek için onay kutusu ve bir kayıt defteri anahtar kullanır.

            try
            {
                // Do something that could generate an exception.
                throw new ApplicationException("An error has occured.");
            }
            catch (ApplicationException ex)
            {
                string str = "The action failed. Do you want to continue?";
                ApplicationException exTop = new ApplicationException(str, ex);
                exTop.Source = this.Text;

                // Show a message box with Yes and No buttons
                ExceptionMessageBox box = new ExceptionMessageBox(exTop,
                    ExceptionMessageBoxButtons.YesNo,
                    ExceptionMessageBoxSymbol.Question,
                    ExceptionMessageBoxDefaultButton.Button2);

                // Enable the check box.
                box.ShowCheckBox = true;

                // Define the registry key to use.
                box.CheckBoxRegistryKey =
                    Microsoft.Win32.Registry.CurrentUser.CreateSubKey(
                    @"Software\TestApp");
                box.CheckBoxRegistryValue = "DontShowActionFailedMessage";
                box.CheckBoxRegistryMeansDoNotShowDialog = true;
                box.DefaultDialogResult = DialogResult.Yes;

                // The message box won’t be displayed if the
                // "DontShowActionFailedMessage" value of the registry key 
                // contains a non-zero value.
                if (box.Show(this) == DialogResult.No)
                {
                    // Do something if the user clicks the No button.
                    this.Close();
                }
            }
Try
    ' Do something that could generate an exception.
    Throw New ApplicationException("An error has occured.")
Catch ex As ApplicationException
    Dim str As String = "The action failed. Do you want to continue?"
    Dim exTop As ApplicationException = New ApplicationException(str, ex)
    exTop.Source = Me.Text

    ' Show a message box with Yes and No buttons
    Dim box As ExceptionMessageBox = New ExceptionMessageBox(exTop, _
     ExceptionMessageBoxButtons.YesNo, _
     ExceptionMessageBoxSymbol.Question, _
     ExceptionMessageBoxDefaultButton.Button2)

    ' Enable the check box.
    box.ShowCheckBox = True

    ' Define the registry key to use.
    box.CheckBoxRegistryKey = _
    Microsoft.Win32.Registry.CurrentUser.CreateSubKey( _
     "Software\TestApp")
    box.CheckBoxRegistryValue = "DontShowActionFailedMessage"
    box.CheckBoxRegistryMeansDoNotShowDialog = True
    box.DefaultDialogResult = Windows.Forms.DialogResult.Yes

    ' The message box won�t be displayed if the
    ' "DontShowActionFailedMessage" value of the registry key 
    ' contains a non-zero value.
    If box.Show(Me) = Windows.Forms.DialogResult.No Then
        ' Do something if the user clicks the No button.
        Me.Close()
    End If
End Try

Bu örnek, sorun giderme veya hata ayıklama sırasında yararlı ek bilgileri göstermek için özel durum iletisi kutusunu kullanır.

          try
            {
                // Do something that you don't expect to generate an exception.
                throw new ApplicationException("Failed to connect to the server.");
            }
            catch (ApplicationException ex)
            {
                string str = "An unexpected error occurred. Please call Helpdesk.";
                ApplicationException exTop = new ApplicationException(str, ex);
                exTop.Source = this.Text;

                // Information in the Data property of an exception that has a name
                // beginning with "HelpLink.Advanced" is shown when the user
                // clicks the Advanced Information button of the exception message
                // box dialog box.
                exTop.Data.Add("AdvancedInformation.FileName", "application.dll");
                exTop.Data.Add("AdvancedInformation.FilePosition", "line 355");
                exTop.Data.Add("AdvancedInformation.UserContext", "single user mode");

                // Show the exception message box with additional information that 
                // is helpful when a user calls technical support.
                ExceptionMessageBox box = new ExceptionMessageBox(exTop);

                box.Show(this);
            }
Try
    ' Do something that you don't expect to generate an exception.
    Throw New ApplicationException("Failed to connect to the server.")
Catch ex As ApplicationException
    Dim str As String = "An unexpected error occurred. Please call Helpdesk."
    Dim exTop As ApplicationException = New ApplicationException(str, ex)
    exTop.Source = Me.Text

    ' Information in the Data property of an exception that has a name
    ' beginning with "HelpLink.Advanced" is shown when the user
    ' clicks the Advanced Information button of the exception message
    ' box dialog box.
    exTop.Data.Add("AdvancedInformation.FileName", "application.dll")
    exTop.Data.Add("AdvancedInformation.FilePosition", "line 355")
    exTop.Data.Add("AdvancedInformation.UserContext", "single user mode")

    ' Show the exception message box with additional information that 
    ' is helpful when a user calls technical support.
    Dim box As ExceptionMessageBox = New ExceptionMessageBox(exTop)

    box.Show(Me)

End Try