我正在逐行阅读文件。
在我的GUI中,我有一个ProgressBar
。但是我想计算ProgressBar
的最大值作为文件的大小,而不是按照我正在阅读的行计算。
如何计算ProgressBar
的值?根据我正在阅读的每个数据后的大小?
感谢。
答案 0 :(得分:3)
您可以通过获取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
}