更改忙碌按钮颜色 [英] Change Busy Button Colour

查看:144
本文介绍了更改忙碌按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




所以我知道如何更改按钮的颜色,但是当按钮忙时可以改变按钮的颜色,因为它通常是浅蓝色的阴影



我一直想知道这个:)并且会喜欢一些帮助请

Hi
So i know how to change the colour of a button, but is it possible to change the colour of the button when the button is busy, as it normally is a shade of light blue

I have always wondered about this :) and would love some help please

推荐答案

一个按钮永远不会忙所以你的问题让人很困惑。



你有问题。 UI线程将被你正在运行的很多代码捆绑在一起,所以改变按钮的颜色直到你的长时间运行代码之后才会做任何事情,因为你已经把UI线程和它不能用新颜色绘制按钮。



您必须将长时间运行的代码移动到一个单独的线程,以便UI线程可以重新绘制按钮。网上有很多关于如何做到这一点的例子,但是你选择哪种技术很大程度上取决于你长期运行的代码在做什么,以及你是否想要支持取消等等。



Google为C#Tasks或C#Backgroundworker提供一些简单方式的例子。
A button is never "busy" so your question is confusing people.

You have a problem. The UI thread will be tied up by your "lot of code" that''s running, so changing the color of the button won''t do anything until AFTER your long running code because you''ve tied up the UI thread and it can''t paint the button in the new color.

You have to move the long running code to a seperate thread so the UI thread can repaint the button. There are tons of examples on the web on how to do that, but which technology you chose pretty much depends on what you''re long running code is doing and if you want to support cancellation and whatnot.

Google for "C# Tasks" or "C# Backgroundworker" for some examples of doing it the "easy" way.


不应该改变颜色,你应该禁用按钮。使用属性 IsEnabled 已启用 - 这取决于您没有费心指定的确切按钮类型。不同的UI库在简单名称Button下具有不同的类。当涉及UI时,您总是需要标记您正在使用的UI库或应用程序类型。



-SA
Instead of changing color, you should disable the button. Use the property IsEnabled or Enabled — it depends on the exact button type you did not bother to specify. Different UI libraries have different classes under the simple name "Button". When UI is involved, you always need to tag UI library or application type you are using.

—SA


这篇关于更改忙碌按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆