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
33 using System.Reflection;
34 using System.ComponentModel;
35 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms
40 [ClassInterface (ClassInterfaceType.AutoDispatch)]
41 public class ThreadExceptionDialog: Form
46 private System.Windows.Forms.Button buttonIgnore;
47 private System.Windows.Forms.Button buttonAbort;
48 private System.Windows.Forms.Button buttonDetails;
49 private System.Windows.Forms.Label labelException;
50 private System.Windows.Forms.Label label1;
51 private System.Windows.Forms.TextBox textBoxDetails;
52 private System.Windows.Forms.Label helpText;
54 private void InitializeComponent()
56 this.helpText = new System.Windows.Forms.Label();
57 this.buttonAbort = new System.Windows.Forms.Button();
58 this.buttonIgnore = new System.Windows.Forms.Button();
59 this.buttonDetails = new System.Windows.Forms.Button();
60 this.labelException = new System.Windows.Forms.Label();
61 this.textBoxDetails = new System.Windows.Forms.TextBox();
62 this.label1 = new System.Windows.Forms.Label();
67 this.helpText.Location = new System.Drawing.Point(60, 8);
68 this.helpText.Name = "helpText";
69 this.helpText.Size = new System.Drawing.Size(356, 40);
70 this.helpText.TabIndex = 0;
71 this.helpText.Text = "An unhandled exception has occurred in you application. If you click Ignore the a" +
72 "pplication will ignore this error and attempt to continue. If you click Abort, t" +
73 "he application will quit immediately.";
77 this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
78 this.buttonAbort.Location = new System.Drawing.Point(332, 112);
79 this.buttonAbort.Name = "buttonAbort";
80 this.buttonAbort.Size = new System.Drawing.Size(85, 23);
81 this.buttonAbort.TabIndex = 4;
82 this.buttonAbort.Text = "&Abort";
83 this.buttonAbort.Click += new System.EventHandler(this.buttonAbort_Click);
87 this.buttonIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
88 this.buttonIgnore.Location = new System.Drawing.Point(236, 112);
89 this.buttonIgnore.Name = "buttonIgnore";
90 this.buttonIgnore.Size = new System.Drawing.Size(85, 23);
91 this.buttonIgnore.TabIndex = 3;
92 this.buttonIgnore.Text = "&Ignore";
96 this.buttonDetails.Location = new System.Drawing.Point(140, 112);
97 this.buttonDetails.Name = "buttonDetails";
98 this.buttonDetails.Size = new System.Drawing.Size(85, 23);
99 this.buttonDetails.TabIndex = 2;
100 this.buttonDetails.Text = "Show &Details";
101 this.buttonDetails.Click += new System.EventHandler(this.buttonDetails_Click);
105 this.labelException.Location = new System.Drawing.Point(60, 64);
106 this.labelException.Name = "labelException";
107 this.labelException.Size = new System.Drawing.Size(356, 32);
108 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;
125 this.label1.Location = new System.Drawing.Point(8, 148);
126 this.label1.Name = "label1";
127 this.label1.Size = new System.Drawing.Size(100, 16);
128 this.label1.TabIndex = 0;
129 this.label1.Text = "Exception details";
131 // ThreadExceptionDialog
133 this.AcceptButton = this.buttonIgnore;
134 this.CancelButton = this.buttonAbort;
135 this.ClientSize = new System.Drawing.Size(428, 374);
136 this.Controls.Add(this.label1);
137 this.Controls.Add(this.textBoxDetails);
138 this.Controls.Add(this.labelException);
139 this.Controls.Add(this.buttonDetails);
140 this.Controls.Add(this.buttonIgnore);
141 this.Controls.Add(this.buttonAbort);
142 this.Controls.Add(this.helpText);
143 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
144 this.MaximizeBox = false;
145 this.MinimizeBox = false;
146 this.Name = "ThreadExceptionDialog";
147 this.ShowInTaskbar = false;
148 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
150 this.Paint += new PaintEventHandler (PaintHandler);
151 this.ResumeLayout(false);
154 public ThreadExceptionDialog (Exception t)
157 InitializeComponent ();
159 this.labelException.Text = t.Message;
160 if (Form.ActiveForm != null)
161 this.Text = Form.ActiveForm.Text;
164 this.buttonAbort.Enabled = Application.AllowQuit;
166 FillExceptionDetails ();
169 void buttonDetails_Click(object sender, System.EventArgs e)
175 void FillExceptionDetails ()
177 StringBuilder sb = new StringBuilder ();
178 sb.Append (e.ToString ());
179 sb.Append (Environment.NewLine + Environment.NewLine);
180 sb.Append ("Loaded assemblies:" + Environment.NewLine + Environment.NewLine);
182 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
183 AssemblyName an = a.GetName ();
184 sb.AppendFormat ("Name:\t{0}" + Environment.NewLine, an.Name);
185 sb.AppendFormat ("Version:\t{0}" + Environment.NewLine, an.Version);
186 sb.AppendFormat ("Location:\t{0}" + Environment.NewLine, an.CodeBase);
187 sb.Append (Environment.NewLine);
189 textBoxDetails.Text = sb.ToString ();
192 void RefreshDetails ()
195 buttonDetails.Text = "Hide &Details";
197 label1.Visible = true;
198 textBoxDetails.Visible = true;
201 buttonDetails.Text = "Show &Details";
202 label1.Visible = false;
203 textBoxDetails.Visible = false;
207 void buttonAbort_Click(object sender, System.EventArgs e)
212 void PaintHandler (object o, PaintEventArgs args)
214 Graphics g = args.Graphics;
215 g.DrawIcon (SystemIcons.Error, 15, 10);
219 [EditorBrowsable (EditorBrowsableState.Never)]
220 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
221 public override bool AutoSize {
222 get { return base.AutoSize; }
223 set { base.AutoSize = value; }
227 [EditorBrowsable (EditorBrowsableState.Never)]
228 public new event EventHandler AutoSizeChanged {
229 add { base.AutoSizeChanged += value; }
230 remove { base.AutoSizeChanged -= value; }