c# – 使用适当的值更新ProgressBar
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 使用适当的值更新ProgressBar,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1750字,纯文字阅读大概需要3分钟。
内容图文
![c# – 使用适当的值更新ProgressBar](/upload/InfoBanner/zyjiaocheng/815/795e8a33130e4d5db39f0ecb51f0db16.jpg)
数学不强,所以这是我的问题:
我正在使用进度条显示在后台执行的工作进度:
我的代码片段:
int i = 0;
int totalFriends = 0;
foreach (dynamic friend in facebookFriends)
{
totalFriends++;
}
foreach (dynamic friend in facebookFriends)
{
i++;
var friend = new FacebookFriend
{
FbId = friend["uid"].ToString()
};
AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
}
现在应用程序做的远不止于此,在这里我只执行一小部分工作:
因此,例如在我到达此部分之前,进度条的值为7,并且在执行工作后它必须达到20并且我想在使用7到20的适当值进行工作时更新它:
我对此的看法如下:
var intiProgressbarValue = 7;
var finalProgressbarvalue = 20;
foreach (dynamic friend in facebookFriends)
{
i++;
var friend = new FacebookFriend
{
FbId = friend["uid"].ToString()
};
AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
var calculatedValue = CalculatedValue(initProgressbarValue, finalProgressBarValue,totalFriends, i);
UpdateProgressBar( calculatedValue);
}
//note that totalFriends can be any number lets say from 0 to 5000
private int CalculatedValue(int initVal, int finalVal, int totalFriends, int currentFriend)
{
int progressBarVal = 0;
//**
Perform logic so it will return a progress value that is bigger that 7 and smaller that 20 depending on the number of friends and currently updated friend
**//
progressBarVal = 8;//this would be the result of calculation, a value from 8 to 20
return progressBarVal;
}
任何帮助非常感谢:
解决方法:
试试这个:
private int CalculatedValue(int initVal, int finalVal, int totalFriends, int currentFriend)
{
initVal++;
var diff = finalVal - initVal; // 20-8 = 12
return (diff*(currentFriend+1))/totalFriends + initVal;
}
这假设currentFriend从0变为totalFriends-1(包括0).例如,如果currentFriend = 99且totalFriends = 300,则此函数返回的答案为12,三分之一到8..20(含)的范围.
内容总结
以上是互联网集市为您收集整理的c# – 使用适当的值更新ProgressBar全部内容,希望文章能够帮你解决c# – 使用适当的值更新ProgressBar所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。