开发者

How to change the value of progressbar in C#?

I want to add an progress bar into my C# based application. I would like to know what is the good way of updating its value at particular events? My problem is, I have single function in UI which does all the processing.T开发者_如何学编程his function in turn calls many more functions, creates objects, updates database, etc. (basically performs all the work) and returns values in an output file. I have access to that function only. So in this how to update the progressbar's value at the end of each step?

What is the best practice for this kind of situation? What is the good way to keep UI logic and business logic seperate? I want to avoid writting progressbar related code in my library code.


Please suggest some solution. Thanks and Regards,


If you have a class that's your "worker class" - the class that you call your single function through - then you can create a Progress property on that class. Then, as the operation proceeds, update the value of that property and throw an event to indicate that it's changed.

You could either define a specific ProgressChanged event or, if you're using data binding, use the INotifyPropertyChanged interface.

Then in your UI: either use databinding, or specifically listen for that event and update the progress bar accordingly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜