0

我是基于 .NET 桌面开发的新手,所以如果我遗漏了一些小东西,请原谅我。

我有一个主表单,当用户单击一个按钮时,会打开一个对话框表单,用户可以在其中选择一些文件,选择文件后,用户单击此表单上的“处理”按钮以开始一个冗长的过程。所以我所做的是单击按钮,隐藏此表单并启动一个后台工作程序,并开始显示另一个对话框以显示动画进度条图像。我面临的问题是当用户单击“处理”按钮时,表单被隐藏并显示进度条对话框,但主表单被最小化。任何机构都可以帮助我吗?我不希望主窗体被最小化。

我选择文件的对话框代码如下:

frmProgressbar progressDialog = null;

private void btnProcess_Click(object sender, EventArgs e)
{
    this.Hide();
    progressDialog = new frmProgressbar();
    worker = new BackgroundWorker();
    worker.WorkerReportsProgress = true;
    worker.WorkerSupportsCancellation = true;
    worker.DoWork += new System.ComponentModel.DoWorkEventHandler(worker_DoWork);
    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
            worker_RunWorkerCompleted);
    worker.RunWorkerAsync();
    progressDialog.ShowDialog();
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
    // Do the lengthy work
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    progressDialog.Close();
}
4

2 回答 2

0

尝试将父窗体提供给 ShowDialog 方法

progressDialog.ShowDialog(this);
于 2013-08-01T11:33:12.373 回答
0
     private Thread progressThread;

 private void Btn_Upload_Click(object sender, EventArgs e)
    {

        Thread.CurrentThread.Priority = ThreadPriority.Highest;
        progressThread = new Thread(new ThreadStart(ShowProgressWindow));
        progressThread.Priority = ThreadPriority.Lowest;
        progressThread.Start(); 

     // do your operation here...
        Class_Upload_SSRD.Search_All_Ptags(Cbox_Ptag_names, label4);
  ///close porcess once ur work is done...
        progressThread.Abort();
        Thread.CurrentThread.Priority = ThreadPriority.Normal;
        this.Show();
    }

//进度条函数

   public void ShowProgressWindow()
    {
        Progress_bar pb = new Progress_bar();
        pb.ShowDialog();
    }

创建进度窗口窗体,执行操作时如图所示 在此处输入图像描述

于 2013-08-01T11:46:11.950 回答