计算每个文件大小的进度条的最大值
calculate the maxmimum of the progress bar per size of file
我正在逐行读取文件。
在我的 GUI 中有一个 ProgressBar
。但是我想计算 ProgressBar
的最大值作为文件的大小,而不是根据我正在阅读的行。
如何计算 ProgressBar
的值?根据我正在读取的每个数据后的大小?
谢谢。
您可以通过FileInfo.Length
获取文件大小
FileInfo fi = FileSystem.GetFileInfo(filepath);
然后在此基础上,你可以将它翻译成 ProgressBar.Value
通过比较你读过的字符数与它相比
int charRead = 0;
foreach(string line in lines){ //get lines whichever way you want
charRead += line.Length + 1; //+1 is for the \n character you throw
double progress = (double)charRead / fi.Length;
//compare charRead with fi.Length
}
我正在逐行读取文件。
在我的 GUI 中有一个 ProgressBar
。但是我想计算 ProgressBar
的最大值作为文件的大小,而不是根据我正在阅读的行。
如何计算 ProgressBar
的值?根据我正在读取的每个数据后的大小?
谢谢。
您可以通过FileInfo.Length
获取文件大小FileInfo fi = FileSystem.GetFileInfo(filepath);
然后在此基础上,你可以将它翻译成 ProgressBar.Value
通过比较你读过的字符数与它相比
int charRead = 0;
foreach(string line in lines){ //get lines whichever way you want
charRead += line.Length + 1; //+1 is for the \n character you throw
double progress = (double)charRead / fi.Length;
//compare charRead with fi.Length
}