//Except where stated all code and programs in this project are the copyright of Jim Blackler, 2008. //jimblackler@gmail.com // //This is free software. Libraries and programs are distributed under the terms of the GNU Lesser //General Public License. Please see the files COPYING and COPYING.LESSER. using System; using System.Windows.Forms; namespace JimBlackler.ExceptionDialog { /// /// Provides a dialog that reports an exception arrising from program error in a clear manner /// for the non-technical user, but with the option of full technical details for the technical /// user. /// public partial class ExceptionDialog : Form { /// /// Makes an exception dialog form /// public ExceptionDialog() { InitializeComponent(); } /// /// The current exception described by the dialog /// public Exception Exception { get { return exception; } set { exception = value; messageTextBox.Text = exception.Message; } } private Exception exception; /// /// Creates and displays a dialog describing an exception. Waits for the user to press /// OK before continuing. /// /// The exception to describe /// A custom title for the dialog static public void ShowDialog(Exception exception, string header) { ExceptionDialog exceptionDialog = new ExceptionDialog(); exceptionDialog.Text = header; exceptionDialog.Exception = exception; exceptionDialog.ShowDialog(); } /// /// Creates and displays a dialog describing an exception. Waits for the user to press /// OK before continuing. /// /// The exception to describe static public void ShowDialog(Exception exception) { ShowDialog(exception, "An error occurred"); } /// /// The user pressed the OK button /// private void okButton_Click(object sender, EventArgs e) { Close(); } /// /// The user clicked the 'Advanced' label /// private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { AdvancedExceptionDialog advancedExceptionDialog = new AdvancedExceptionDialog(); advancedExceptionDialog.Exception = Exception; advancedExceptionDialog.ShowDialog(); } } }