|
using Hydro.CommonBase;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Diagnostics;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
|
namespace Hydro.MapUI
|
{
|
public partial class ProgressForm_计算 : Form
|
{
|
private Thread progressThread;
|
public ProgressForm_计算()
|
{
|
InitializeComponent();
|
}
|
|
private void ProgressForm_Load(object sender, EventArgs e)
|
{
|
StartProgressThread();
|
this.Activate();
|
|
}
|
private void StartProgressThread()
|
{
|
progressThread = new Thread(UpdateProgress);
|
progressThread.IsBackground = true;
|
progressThread.Start();
|
}
|
|
private void StopProgressThread()
|
{
|
if (progressThread != null && progressThread.IsAlive)
|
{
|
progressThread.Abort();
|
}
|
}
|
bool isHided = false;
|
//public void reSetProgress()
|
//{
|
// BeginInvoke(new Action(() =>
|
// {
|
// progressBar1.Value = 0;
|
// }));
|
//}
|
private void UpdateProgress()
|
{
|
while (!GlobalProgress.NeedStop)
|
{
|
if (GlobalProgress.Hide)
|
{
|
BeginInvoke(new Action(() =>
|
{
|
this.Size = new System.Drawing.Size(0, 0);
|
}));
|
}
|
else
|
if (!GlobalProgress.Hide)
|
{
|
BeginInvoke(new Action(() =>
|
{
|
this.Size = new System.Drawing.Size(419, 178);
|
}));
|
}
|
|
|
string stateText = GlobalProgress.stateText;
|
int maxNum = GlobalProgress.MaxNum;
|
int currentNum = GlobalProgress.CurrentNum;
|
|
|
int childmaxNum = GlobalProgress.ChildMaxNum;
|
int childcurrentNum = GlobalProgress.ChildCurrentNum;
|
string childText = GlobalProgress.ChildText;
|
|
lock (GlobalProgress.Instance)
|
{
|
stateText = GlobalProgress.stateText;
|
maxNum = GlobalProgress.MaxNum;
|
currentNum = GlobalProgress.CurrentNum;
|
|
childmaxNum = GlobalProgress.ChildMaxNum;
|
childcurrentNum = GlobalProgress.ChildCurrentNum;
|
}
|
|
// 使用 Invoke 方法让 UI 线程更新控件
|
BeginInvoke(new Action(() =>
|
{
|
|
if (GlobalProgress.mode == 0)
|
{
|
label1.Text = $"{stateText}[{currentNum}/{maxNum}]";
|
progressBar1.Maximum = maxNum * 150;
|
List<int> nums = new List<int>();
|
nums.Add(0);
|
nums.Add(progressBar1.Maximum * 4 / 5);
|
|
int span = 0;
|
if (maxNum > 1) span = (int)(progressBar1.Maximum / 5.0 / (maxNum - 1));
|
for (int i = 1; i < maxNum; i++)
|
{
|
nums.Add(nums[i - 1] + span);
|
}
|
|
if (currentNum < nums.Count && progressBar1.Value < nums[currentNum])
|
{
|
progressBar1.Value = nums[currentNum];
|
progressBar2.Value = 0;
|
}
|
|
else if (currentNum + 1 < nums.Count && progressBar1.Value < (nums[currentNum + 1]))
|
progressBar1.Value = Math.Min(progressBar1.Value + 2, progressBar1.Maximum);
|
metroLabel1.Text = $"{childText}[{childcurrentNum}/{childmaxNum}]";
|
progressBar2.Maximum = childmaxNum * 100;
|
if (progressBar2.Value < childcurrentNum * 100)
|
progressBar2.Value = Math.Min(childcurrentNum * 100, progressBar2.Maximum);
|
else if (progressBar2.Value < (childcurrentNum + 1) * 100)
|
progressBar2.Value = Math.Min(progressBar2.Value + 4, progressBar2.Maximum);
|
}
|
else
|
{
|
label1.Text = $"{stateText}[{currentNum}/{maxNum}]";
|
progressBar1.Maximum = maxNum;
|
progressBar1.Value = currentNum;
|
}
|
|
//this.Activate();
|
}));
|
|
Thread.Sleep(100); // 每隔0.1秒检索一次
|
}
|
BeginInvoke(new Action(() =>
|
{
|
this.Hide();
|
}));
|
|
}
|
|
|
|
private void ProgressForm_FormClosing(object sender, FormClosingEventArgs e)
|
{
|
StopProgressThread();
|
}
|
|
private void label1_Click(object sender, EventArgs e)
|
{
|
|
}
|
}
|
}
|