日期:2014-05-18 浏览次数:21243 次
    public class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.OnDoSomething += new EventHandler(frm_OnDoSomething);
            frm.ShowDialog();
            MessageBox.Show("查询完成");
        }
        void frm_OnDoSomething(object sender, EventArgs e)
        {
            //在此处写入你需要查询的操作
            System.Threading.Thread.Sleep(3000);
        }
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;
        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #region Windows 窗体设计器生成的代码
        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(309, 172);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(658, 419);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
        }
        #endregion
        private System.Windows.Forms.Button button1;
    }
------解决方案--------------------
thread th=new thread(new threadstart());
th.start();
public void showwaritform(object obj)
{
  using(Waitform frm=new Waitform)
{
frm.topmoast=true;
frm.showdialog();
}
}
public class Waitform:Form
{
public Waitform()
{
  //加个Timer 定时几秒把这个窗口close就可以了。
}
Waitform_onload (object sender)
{
  
}
}
这种方法界面不会卡住。