从软考完就正式 的开始了我们计算机一级的开发,周洲把 word这个大的模块交给我,刚开始的时候感觉还是挺难的,好多的属性找不到,因此也就好多的代码不会写!可是黄天不负有心人,经过师哥的指导,加上自己的悟性,代码这一块也可以说解决了大部分的难题!
![](https://img-blog.csdn.net/20151218083537907?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
到2个星期前,一直有一个待解决的问题就是:判分的时候用到了进度条!所以我就在敲代码闲下来的时候研究了一下这个进度条。可是我写的进度条是由timer控件控制的,所以单个显示的时候没有问题,但是想要它一边判分一边滚动就有难度了!
可是上个星期,让海滨师哥给我解决另一个问题的时候就顺便解决了这个问题,真是不得不感慨一下:做项目多了就是思路广啊!一下子就想到了用多进程!
接下来就是代码:
先新建一个窗体,里面放上进度条,设置进度条的各种属性:
如下:
接下来是进度条窗体的代码:
public partial class frmWaitting : Form
{
public frmWaitting(System.ComponentModel.BackgroundWorker worker)
{
InitializeComponent();
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
}
private void label2_Click(object sender, EventArgs e)
{
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Close();
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
//lblStatus.Text = "数据加载中...";
}
}
这是整个判分窗体的逻辑:
public partial class FrmJudge : Form
{
BackgroundWorker worker;
public static Form frmjudge;
public static frmxuanfukuang xuanfu;
public FrmJudge()
{
InitializeComponent();
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
frmjudge = this;
}
#region 异步 开始事件
/// <summary>
/// 异步 开始事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
#region 进行评分操作 2015年12月14日13:52:43 李少然
string studentID;
studentID = MyInfo.MystudentID();
#region Word判分 2015年11月23日
WordQuestionEntityBLL wordquestionbll = new WordQuestionEntityBLL();
WordQuestionEntity wordinfo = new WordQuestionEntity();
StudentInfoEntity studentinfo = new StudentInfoEntity();
wordinfo.PaperType = MyInfo.MyPaperType();
switch (MyInfo.MyPaperType().Trim())
{
case "A":
//判断表格C是否存在
string filePath = @"D:\计算机一级考生文件\Wordkt\bgA.docx";
if (MyInfo.exitsDoc(filePath))
{
WordAQuestionFlag wordquestionflag = new WordAQuestionFlag();
wordquestionflag.SwitchQuestionFlag(wordinfo);
}
break;
case "B":
//判断表格C是否存在
string filePathB = @"D:\计算机一级考生文件\Wordkt\bgB.docx";
if (MyInfo.exitsDoc(filePathB))
{
WordBQuestionFlag wordBquestionflag = new WordBQuestionFlag();
wordBquestionflag.SwitchQuestionFlagB(wordinfo);
}
break;
case "C":
//判断表格C是否存在
string filePathC = @"D:\计算机一级考生文件\Wordkt\bgC.docx";
if (MyInfo.exitsDoc(filePathC))
{
WordCQuestionFlag wordCquestionflag = new WordCQuestionFlag();
wordCquestionflag.SwitchQuestionFlagC(wordinfo);
}
break;
case "D":
//判断表格C是否存在
string filePathD = @"D:\计算机一级考生文件\Wordkt\bgD.docx";
if (MyInfo.exitsDoc(filePathD))
{
WordDQuestionFlag wordDquestionflag = new WordDQuestionFlag();
wordDquestionflag.SwitchQuestionFlagD(wordinfo);
}
break;
case "E":
//判断表格C是否存在
string filePathE = @"D:\计算机一级考生文件\Wordkt\bgE.docx";
if (MyInfo.exitsDoc(filePathE))
{
WordEQuestionFlag wordEquestionflag = new WordEQuestionFlag();
wordEquestionflag.SwitchQuestionFlagE(wordinfo);
}
break;
case "F":
//判断表格C是否存在
string filePathF = @"D:\计算机一级考生文件\Wordkt\bgF.docx";
if (MyInfo.exitsDoc(filePathF))
{
WordFQuestionFlag wordFquestionflag = new WordFQuestionFlag();
wordFquestionflag.SwitchQuestionFlagF(wordinfo);
}
break;
case "G":
//判断表格C是否存在
string filePathG = @"D:\计算机一级考生文件\Wordkt\bgG.docx";
if (MyInfo.exitsDoc(filePathG))
{
WordGQuestionFlag wordGquestionflag = new WordGQuestionFlag();
wordGquestionflag.SwitchQuestionFlagG(wordinfo);
}
break;
case "H":
//判断表格C是否存在
string filePathH = @"D:\计算机一级考生文件\Wordkt\bgH.docx";
if (MyInfo.exitsDoc(filePathH))
{
WordHQuestionFlag wordHquestionflag = new WordHQuestionFlag();
wordHquestionflag.SwitchQuestionFlagH(wordinfo);
}
break;
default:
break;
}
TypeSumFrationBLL typesumfration = new TypeSumFrationBLL();
typesumfration.WordSumFration(studentID);
//MessageBox.Show("word判分成功!");
//txtMsg.Text += "\r\nword判分成功!";
}
#endregion
#region 异步执行完成后
/// <summary>
/// 事件: 异步执行完成后
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//显示图片
MessageBox.Show("评分完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
frmjudge.Hide();
}
#endregion
private void FrmJudge_Load_1(object sender, EventArgs e)
{
worker.RunWorkerAsync();
//显示进度窗体
frmWaitting frm = new frmWaitting(this.worker);
frm.StartPosition = FormStartPosition.CenterScreen;
frm.ShowDialog(this);
}
}
最后的显示效果,和你选择的进度条的属性是相关的,可是却可以随着判分而随时的显示,如下:
小总:
自己在研究进度条的时候根本没有想到要用多进程来控制,可是师哥却是“看到即想到”,这就是经验,希望自己将来也能和师哥一样优秀!多谢师哥的帮忙,可是自己也要多加努力啊!fighiting!