用模式窗体显示进度

gaoqi9902 2008-02-19 09:00:24
我做了一个函数,在函数中我读取仪器的各个设置参数,这个函数处理的时间很长,主要是要调用底层的仪器驱动,我想在用户点击按钮以后弹出一个进度窗体,可以报告用户当前的程序正在读取哪个参数。
...全文
106 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lljfl 2008-02-19
  • 打赏
  • 举报
回复
//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显示提示
rangeon 2008-02-19
  • 打赏
  • 举报
回复
既然读取仪器数据的代码会写,这个小小的进度窗口能难倒你吗?加油

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧