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

📄 testform.cs

📁 功能:基于windows mobile 的地图查看器。使用vs2005开发
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace PInvokeLibrary
{
	/// <summary>
	/// Summary description for TestForm.
	/// </summary>
	public class TestForm : System.Windows.Forms.Form
	{
		static void Main() 
		{
			Application.Run(new TestForm());
		}

		private System.Windows.Forms.Button button_test;
		private System.Windows.Forms.Button button_clear;
		private System.Windows.Forms.ListBox listBox_tests;
		private System.Windows.Forms.ListBox listBox_results;

		public TestForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button_test = new System.Windows.Forms.Button();
			this.button_clear = new System.Windows.Forms.Button();
			this.listBox_tests = new System.Windows.Forms.ListBox();
			this.listBox_results = new System.Windows.Forms.ListBox();
			// 
			// button_test
			// 
			this.button_test.Location = new System.Drawing.Point(136, 24);
			this.button_test.Size = new System.Drawing.Size(96, 32);
			this.button_test.Text = "Run Test";
			this.button_test.Click += new System.EventHandler(this.button_test_Click);
			// 
			// button_clear
			// 
			this.button_clear.Location = new System.Drawing.Point(136, 80);
			this.button_clear.Size = new System.Drawing.Size(96, 32);
			this.button_clear.Text = "Clear Results";
			this.button_clear.Click += new System.EventHandler(this.button_clear_Click);
			// 
			// listBox_tests
			// 
			this.listBox_tests.Location = new System.Drawing.Point(8, 16);
			this.listBox_tests.Size = new System.Drawing.Size(120, 100);
			// 
			// listBox_results
			// 
			this.listBox_results.Location = new System.Drawing.Point(8, 128);
			this.listBox_results.Size = new System.Drawing.Size(224, 128);
			// 
			// TestForm
			// 
			this.Controls.Add(this.listBox_results);
			this.Controls.Add(this.listBox_tests);
			this.Controls.Add(this.button_clear);
			this.Controls.Add(this.button_test);
			this.MinimizeBox = false;
			this.Text = "PInvoke Test";
			this.Load += new System.EventHandler(this.TestForm_Load);

		}
		#endregion

		/// <summary>
		/// Instance of the MainTest class which enumerates available test methods
		/// in the current Assembly.
		/// </summary>
		protected MainTest m_test = null;

		/// <summary>
		/// For safety, do not allow the Form to close while a test is in progress.
		/// </summary>
		protected bool m_waitToClose = false;

		/// <summary>
		/// Specifies if a Close was attempted during a test.
		/// </summary>
		protected bool m_closeRequested = false;

		/// <summary>
		/// Displays a line of text to the the results box.  This method is supplied
		/// to m_test for providing test feedback.
		/// </summary>
		/// <param name="line">Text to be displayed</param>
		protected void ShowResultLine(String line)
		{
			this.listBox_results.Items.Add(line);
			this.listBox_results.SelectedIndex = this.listBox_results.Items.Count - 1;
		}

		/// <summary>
		/// When the Test button is clicked, run the selected test.
		/// </summary>
		private void button_test_Click(object sender, System.EventArgs e)
		{
			if (this.listBox_tests.SelectedIndex == -1)
				return;

			m_waitToClose = true;

			this.button_clear.Enabled = false;
			this.button_test.Enabled = false;

			// Index 0 is All Tests
			if (this.listBox_tests.SelectedIndex > 0)
			{
				m_test.RunTest(this.listBox_tests.SelectedIndex - 1);
			}
			else
			{
				for (int i = 0; i < m_test.NumTests; i++)
				{
					m_test.RunTest(i);
					Application.DoEvents();

					if (m_closeRequested)
						break;
				}
			}

			this.button_clear.Enabled = true;
			this.button_test.Enabled = true;

			m_waitToClose = false;

			if (m_closeRequested)
			{
	            ShowResultLine("OK to close now");
				m_closeRequested = false;
			}		
		}

		/// <summary>
		/// When the Clear button is pressed, clear the results box.
		/// </summary>
		private void button_clear_Click(object sender, System.EventArgs e)
		{
			this.listBox_results.Items.Clear();
		}

		/// <summary>
		/// Initialize the MainTest instance and use it to fill the
		/// test selection box.
		/// </summary>
		private void TestForm_Load(object sender, System.EventArgs e)
		{
			m_test = new MainTest
			(
				new MainTest.DisplayLineDelegate(this.ShowResultLine)
			);

			this.listBox_tests.Items.Clear();
			this.listBox_tests.Items.Add("All Tests");
			for (int i = 0; i < m_test.NumTests; i++)
			{
				this.listBox_tests.Items.Add(m_test.GetTestName(i));
			}
		}

		/// <summary>
		/// It is not safe to close the Form during test execution so
		/// wait until it is completed first.
		/// </summary>
		protected override void OnClosing(CancelEventArgs e)
		{
			if (m_waitToClose)
			{
				ShowResultLine("WARNING: Cannot close until");
				ShowResultLine("test is complete!");
				m_closeRequested = true;
				e.Cancel = true;
			}

			base.OnClosing (e);
		}
	}
}

⌨️ 快捷键说明

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