using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; namespace WaitForm ...{ publicpartialclass FrmMain : Form ...{ private DataTable dt; public FrmMain() ...{ InitializeComponent(); } public FrmMain(Thread th) ...{ InitializeComponent(); this.m_thWait = th; } publicstaticint m_number =0; privatevoid FrmMain_Load(object sender, EventArgs e) ...{ dt =new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Pwd", typeof(string)); if (m_thWait ==null) ...{ 初始化模拟数据 快捷键提示(当你敲入"#region"后请按"Tab"键2次,就会出现完整的#region#endregion字段范围)#region 初始化模拟数据 快捷键提示(当你敲入"#region"后请按"Tab"键2次,就会出现完整的#region#endregion字段范围) for (int i =0; i <10; i++) ...{ DataRow dr = dt.NewRow(); dr[0] ="name"+ i; dr[1] = i.ToString() +"-"+ i.ToString(); dt.Rows.Add(dr); } this.dgv.DataSource = dt; #endregion this.buttonQuery.Click +=new EventHandler(buttonQuery_Click); } else//选择查询按钮后触发 ...{ this.buttonQuery.Visible =false; for (int i =0; i <100000; i++) ...{ m_number = i; DataRow dr = dt.NewRow(); dr[0] ="name"+ i; dr[1] = i.ToString() +"-"+ i.ToString(); dt.Rows.Add(dr); } this.dgv.DataSource = dt; try ...{ if (m_thWait !=null) m_thWait.Abort(); } catch (Exception ex) ...{ MessageBox.Show(ex.Message); } } this.buttonClose.Click +=new EventHandler(buttonClose_Click); } void buttonClose_Click(object sender, EventArgs e) ...{ this.Close(); } private System.Threading.Thread m_thWait; void buttonQuery_Click(object sender, EventArgs e) ...{ m_thWait =new Thread(run); try ...{ m_thWait.Start(); FrmMain frmResult =new FrmMain(m_thWait); frmResult.ShowDialog(); } catch (Exception ex) ...{ MessageBox.Show(ex.Message); } } void run() ...{ FrmWait frmWait =new FrmWait(); frmWait.ShowDialog(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WaitForm ...{ publicpartialclass FrmWait : Form ...{ public FrmWait() ...{ InitializeComponent(); } //请测试者自己添加一个计数器 privatevoid timer1_Tick(object sender, EventArgs e) ...{ label1.Text = FrmMain.m_number.ToString(); } } }