我做了一个函数,在函数中我读取仪器的各个设置参数,这个函数处理的时间很长,主要是要调用底层的仪器驱动,我想在用户点击按钮以后弹出一个进度窗体,可以报告用户当前的程序正在读取哪个参数。

解决方案 »

  1.   

    //from1代码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 WindowsApplication4
    {
        public partial class Form1 : Form
        {
            private Form2 frm= new Form2();
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Thread th1 = new Thread(new ThreadStart(show));
                th1.Start();
                
                Thread th = new Thread(new ThreadStart(start));
                th.Start();
            }        private void Form1_Load(object sender, EventArgs e)
            {         }
            private void start()
            {
                frm.SetLableText("开始");
                Thread.Sleep(3000);
                frm.SetLableText("1");
                Thread.Sleep(3000);
                frm.SetLableText("结束");
            }
            private void show()
            {
                frm.ShowDialog();
            }
        }
    //form2代码using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication4
    {
        public partial class Form2 : Form
        {
            delegate void SetLableTextCallback(string str);
            public Form2()
            {
                InitializeComponent();
            }        public void SetLableText(string str)
            {
                if (label1.InvokeRequired)
                {
                    SetLableTextCallback d = new SetLableTextCallback(SetLableText);
                    this.Invoke(d, new object[] { str });
                }
                else
                {
                    label1.Text = str;
                }
            }
            private void Form2_Load(object sender, EventArgs e)
            {        }
           
        }
    }//from1窗体有一个buuton,form2有一个lable,在lable显示提示