using Iterateds.Properties;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Iterateds {
public partial class Main : Form {
public static readonly int Max = 10;
public static List<string> Files = new List<string>();
public static int CountFiles = 0,
Threaded = 0,
Counters = 0;
public Main() {
string File;
StringReader strReader = new StringReader(Resources.files.Trim());
while (null != (File = strReader.ReadLine())) {
Files.Add(File);
}
CountFiles = Files.Count;
InitializeComponent();
}
public void Iterated() {
if (0 >= Files.Count) {
return;
}
string selectPath = this.selectPath?.Text;
if (string.IsNullOrEmpty(selectPath.Trim())) {
return;
}
int Counter = 0;
foreach (string file in Files) {
if (Main.Counters >= Counter) {
++Counter;
continue;
}
if (Max > Threaded) {
string filed = file.Trim();
if (string.IsNullOrEmpty(filed)) {
continue;
}
// -----------------------------------------------
// -----------------------------------------------
// -----------------------------------------------
//////////////////////////
// THE PROBLEM IS HERE: //
//////////////////////////
ListViewItem item = new ListViewItem(filed);
ProgressBar pb = new ProgressBar {
Maximum = 100
};
this.Logs.Items.Add(item);
Rectangle r = item.Bounds;
pb.SetBounds(r.X, r.Y, r.Width, r.Height);
this.Logs.Controls.Add(pb);
///////////////////////////////
// ^^ THE PROBLEM IS HERE ^^ //
///////////////////////////////
// -----------------------------------------------
// -----------------------------------------------
// -----------------------------------------------
// here is the load manager, after we reach "Threaded" it starts "Iterated" again to take another "Max" or the remainder if less.
++Threaded;
}
}
}
}
}问题是,当第一次添加时,一切都很好,但是我意识到它们坚持在屏幕上,在下一次迭代之后,它们不再出现在进度条上,或者出现在一个位置下面的某个地方,就好像它就在1,并且文件本身的路径会根据需要显示出来。
这个问题可能是由pb.SetBounds引起的,因为ListView有一个滚动条,滚动和所有东西都会崩溃,也许有人会告诉你如何解决这个问题?
我需要左边的文件地址,右边的进度条,不需要其他任何东西。
每次函数都不应该超过Max。
也就是说,一次只能处理Max或更少的文件。
发布于 2022-09-18 14:45:06
没有ListView就有可能通过TableLayoutPanel解决问题。
this.tableLayoutPanel1.RowCount += 1;
Label txt = new Label {
Text = filed
};
txt.AutoSize = true;
ProgressBar pb = new ProgressBar {
Maximum = 100
};
pb.Height = 10;
this.tableLayoutPanel1.Controls.Add(txt);
this.tableLayoutPanel1.Controls.Add(pb);https://stackoverflow.com/questions/73761779
复制相似问题