[英]C# Call the same function with different values at the same time
I have a function that changes the text in a label for another one, showing the text transition effect. 我有一个功能,可以将标签中的文本更改为另一个,以显示文本过渡效果。 Imagine that I have 4 labels with texts, and I want to replace their texts with another different ones, showing the same effect but for the 4 labels at the same time, is there any way to do that?
想象一下,我有4个带有文本的标签,并且我想用另一个不同的文本替换它们的文本,显示出相同的效果,但是同时对4个标签,有什么办法可以做到这一点? Call the same function with different values at the same time.
同时调用具有不同值的相同函数。
Thanks in >> 谢谢>>
I would recommend using double-buffering to achieve this effect. 我建议使用双缓冲来达到这种效果。 You update the labels, and then use double-buffering to show the completed form.
您更新标签,然后使用双缓冲来显示完成的表单。 There are plenty of articles on enabling this for WinForms apps, and the concept is applicable to most UI platforms.
关于为WinForms应用启用此功能的文章很多,该概念适用于大多数UI平台。
Windows UI (for WinForms at least) doesn't like to be updated from multiple threads, so I wouldn't bother trying to pursue that (unless you require a lot of background computation to get the new values) Windows UI(至少适用于WinForms)不喜欢从多个线程进行更新,因此我不会费心尝试这种方法(除非您需要大量后台计算才能获取新值)
You can modify your function to change all labels at once. 您可以修改功能以一次更改所有标签。 Something like this:
像这样:
Foreach EffectStep
Foreach Label
do some job
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.