/// <summary> /// Used to create a custom app exception dialog. /// </summary> /// <param name="sender"><see cref="Form1.cmdApplicationExceptionDialog_Click"/>Calling form</param> /// <param name="ex">ApplicationException instance</param> /// <param name="title">Title for dialog</param> /// <returns>ExceptionMessageBoxDialogResult</returns> /// <remarks> /// https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.messagebox.exceptionmessagebox?view=sqlserver-2016 /// </remarks> public static ExceptionMessageBoxDialogResult AppExceptionDialog(Form sender, ApplicationException ex, string title = "Action failed. What do you want to do?") { var applicationException = new ApplicationException(title, ex) { Source = "Source" }; // Show the exception message box with three custom buttons. var box = new ExceptionMessageBox(applicationException) { Caption = "Karen's great application" }; // set the window caption/title // 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(sender); return(box.CustomDialogResult); }
private void button3_Click(object sender, EventArgs e) { //<snippetemb_showcustombutton> 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; } } //</snippetemb_showcustombutton> }
private void HandleException(IWin32Window owner, Exception ex) { string message; BasicGoogleTelemetry.SendExtendedExceptionHit(ex, false, TelemetryScreenName, TelemetryScreenName); var isSocket = ex as SocketException; var isTimeout = ex as TimeoutException; message = TextDownloadException ?? Properties.Texts.HelperExceptionText; if (isSocket != null) { message = string.Format(Properties.Texts.SocketException, message, isSocket.SocketErrorCode); } else if (isTimeout != null) { message = string.Format(Properties.Texts.TimeoutException, message); } var box = new ExceptionMessageBox() { Buttons = ExceptionMessageBoxButtons.Custom, InnerException = ex, Text = message, DefaultButton = ExceptionMessageBoxDefaultButton.Button2, CustomSymbol = Properties.Resources.DvbStpDownload_Error_48x48 }; box.SetButtonText(ExceptionMessageBox.OKButtonText, Properties.Texts.HandleExceptionHelpButton); box.Show(owner); if (box.CustomDialogResult == ExceptionMessageBoxDialogResult.Button2) { BasicGoogleTelemetry.SendEventHit("ShowDialog", "UiServices.DvbStpClient.HelpDialog", TelemetryScreenName, TelemetryScreenName); HelpDialog.ShowRtfHelp(owner, Properties.Texts.RtfTroubleshootingGuide, null); } // if } // HandleException