2 // System.Windows.Forms.ThreadExceptionDialog.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 // Marek Safar marek.safar@seznam.cz
26 // Copyright (C) Novell Inc., 2004
28 // COMPLETE - BUT DISABLED TEXTBOX
32 using System.Reflection;
34 namespace System.Windows.Forms
36 public class ThreadExceptionDialog: Form
41 private System.Windows.Forms.Button buttonIgnore;
42 private System.Windows.Forms.Button buttonAbort;
43 private System.Windows.Forms.Button buttonDetails;
44 private System.Windows.Forms.Label labelException;
45 private System.Windows.Forms.Label label1;
47 private System.Windows.Forms.TextBox textBoxDetails;
49 private System.Windows.Forms.Label helpText;
51 private void InitializeComponent()
53 this.helpText = new System.Windows.Forms.Label();
54 this.buttonAbort = new System.Windows.Forms.Button();
55 this.buttonIgnore = new System.Windows.Forms.Button();
56 this.buttonDetails = new System.Windows.Forms.Button();
57 this.labelException = new System.Windows.Forms.Label();
59 this.textBoxDetails = new System.Windows.Forms.TextBox();
61 this.label1 = new System.Windows.Forms.Label();
66 this.helpText.Location = new System.Drawing.Point(60, 8);
67 this.helpText.Name = "helpText";
68 this.helpText.Size = new System.Drawing.Size(356, 40);
69 this.helpText.TabIndex = 0;
70 this.helpText.Text = "An unhandled exception has occurred in you application. If you click Ignore the a" +
71 "pplication will ignore this error and attempt to continue. If you click Abort, t" +
72 "he application will quit immediately.";
76 this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
77 this.buttonAbort.Location = new System.Drawing.Point(332, 112);
78 this.buttonAbort.Name = "buttonAbort";
79 this.buttonAbort.Size = new System.Drawing.Size(85, 23);
80 this.buttonAbort.TabIndex = 4;
81 this.buttonAbort.Text = "&Abort";
82 this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
86 this.buttonIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
87 this.buttonIgnore.Location = new System.Drawing.Point(236, 112);
88 this.buttonIgnore.Name = "buttonIgnore";
89 this.buttonIgnore.Size = new System.Drawing.Size(85, 23);
90 this.buttonIgnore.TabIndex = 3;
91 this.buttonIgnore.Text = "&Ignore";
95 this.buttonDetails.Location = new System.Drawing.Point(140, 112);
96 this.buttonDetails.Name = "buttonDetails";
97 this.buttonDetails.Size = new System.Drawing.Size(85, 23);
98 this.buttonDetails.TabIndex = 2;
99 this.buttonDetails.Text = "Show &Details";
100 this.buttonDetails.Click += new System.EventHandler(this.buttonDetails_Click);
104 this.labelException.Location = new System.Drawing.Point(60, 64);
105 this.labelException.Name = "labelException";
106 this.labelException.Size = new System.Drawing.Size(356, 32);
107 this.labelException.TabIndex = 1;
112 this.textBoxDetails.Location = new System.Drawing.Point(8, 168);
113 this.textBoxDetails.Multiline = true;
114 this.textBoxDetails.Name = "textBoxDetails";
115 this.textBoxDetails.ReadOnly = true;
116 this.textBoxDetails.ScrollBars = System.Windows.Forms.ScrollBars.Both;
117 this.textBoxDetails.Size = new System.Drawing.Size(408, 196);
118 this.textBoxDetails.TabIndex = 5;
119 this.textBoxDetails.TabStop = false;
120 this.textBoxDetails.Text = "";
121 this.textBoxDetails.WordWrap = false;
126 this.label1.Location = new System.Drawing.Point(8, 148);
127 this.label1.Name = "label1";
128 this.label1.Size = new System.Drawing.Size(100, 16);
129 this.label1.TabIndex = 0;
130 this.label1.Text = "Exception details";
132 // ThreadExceptionDialog
134 this.AcceptButton = this.buttonIgnore;
135 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
136 this.CancelButton = this.buttonAbort;
137 this.ClientSize = new System.Drawing.Size(428, 374);
138 this.Controls.Add(this.label1);
140 this.Controls.Add(this.textBoxDetails);
142 this.Controls.Add(this.labelException);
143 this.Controls.Add(this.buttonDetails);
144 this.Controls.Add(this.buttonIgnore);
145 this.Controls.Add(this.buttonAbort);
146 this.Controls.Add(this.helpText);
147 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
148 this.MaximizeBox = false;
149 this.MinimizeBox = false;
150 this.Name = "ThreadExceptionDialog";
151 this.ShowInTaskbar = false;
152 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
154 this.ResumeLayout(false);
157 public ThreadExceptionDialog (Exception e)
160 InitializeComponent ();
162 this.labelException.Text = e.Message;
163 if (Form.ActiveForm != null)
164 this.Text = Form.ActiveForm.Text;
167 this.buttonAbort.Enabled = Application.AllowQuit;
169 FillExceptionDetails ();
172 void buttonDetails_Click(object sender, System.EventArgs e)
178 void FillExceptionDetails ()
180 StringBuilder sb = new StringBuilder ();
181 sb.Append (e.ToString ());
182 sb.Append (Environment.NewLine + Environment.NewLine);
183 sb.Append ("Loaded assemblies:" + Environment.NewLine + Environment.NewLine);
185 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
186 AssemblyName an = a.GetName ();
187 sb.AppendFormat ("Name:\t{0}" + Environment.NewLine, an.Name);
188 sb.AppendFormat ("Version:\t{0}" + Environment.NewLine, an.Version);
189 sb.AppendFormat ("Location:\t{0}" + Environment.NewLine, an.CodeBase);
190 sb.Append (Environment.NewLine);
193 textBoxDetails.Text = sb.ToString ();
197 void RefreshDetails ()
200 buttonDetails.Text = "Hide &Details";
204 buttonDetails.Text = "Show &Details";
208 void buttonAbort_Click(object sender, System.EventArgs e)