⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample15.cs

📁 C#函数手册
💻 CS
字号:
namespace apiBook
{
	/*本程序来自MSDN*/
	using System;
	using System.ComponentModel;
	using System.Data;
	using System.Drawing;
	using System.Windows.Forms;
	public class testAnimateImage : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		
		//private Button button1;
	//	private Button button2;
		private ListBox  listBox1;   
	//	private DataSet myDataSet;
	//	private bool TablesAlreadyAdded;
		public testAnimateImage()
		{			
			
		}
		public static void Main()     
		{
				TestExceptionHandler testE = new TestExceptionHandler(); 
			Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(testE.OnThreadException);
			Application.Run(new Form1());
			//使用Run方法在当前线程上开始运行标准应用程序消息循环
		}
		private void button1_Click(object sender, System.EventArgs e)
		{
			int i = 5;
			string str=null;
			for(int j=1; j<=i; j++) 
			{
				str+=j;
			}			
			listBox1.Items.Add(str);
			if (MessageBox.Show("退出应用程序吗?", "", 
				MessageBoxButtons.YesNo) == DialogResult.No) 
			{
				MessageBox.Show("请继续使用");
			} 		
		}
		private void button2_Click(object sender, System.EventArgs e)
		{
			throw new ArgumentException("找不到匹配项");
		}
		private void button3_Click(object sender, System.EventArgs e)
		{
			Application.Exit();		
			//使用Exit方法退出应用程序
		}
	}
	internal class TestExceptionHandler 
	{
		public void OnThreadException(object sender,System.Threading.ThreadExceptionEventArgs t) 
		{   
			//使用OnThreadException方法引发 ThreadException 事件
			DialogResult result = DialogResult.Cancel;
			try
			{
					result = this.ShowThreadExceptionDialog(t.Exception);
			}
			catch
			{
					try
			 {
				 MessageBox.Show("严重错误", "严重错误", 
					 MessageBoxButtons.AbortRetryIgnore, 
					 MessageBoxIcon.Stop);
			 }
			 finally
			 {
				 Application.Exit();
			 }
			}
			if (result == DialogResult.Abort) 
				Application.Exit();
		}
		private DialogResult ShowThreadExceptionDialog(Exception e) 
		{
				string errMsg="请和管理员联系,该程序出现以下错误:	 \n\n";errMsg = errMsg + e.Message + "\n\n栈跟踪结果:\n" + e.StackTrace;
																  return MessageBox.Show(errMsg,"应用程序错误:", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
		}  
	}

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -