cloudflight
2024-06-10 07ffb6029da759a8ce4498207cfa5f6d069c44b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 
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)
        {
 
        }
    }
}