我可以一键更改按钮文本多次 [英] Can I Do Change The Button Text Multi Time In One Click

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

问题描述

我有一个按钮,想要一次点击多次更改按钮文本。当用户点击按钮时,按钮文本将变为正在完成...,一段时间后它将再次变为已完成

i have a button and wanted to change the button text multi time in one click. when a user click the button, button text will be change in to "completing..." and after some time it will again change into "completed"

推荐答案

是,你可以做到......但究竟如何取决于很多因素。

1)环境。基于Web的应用程序的方法与基于Windows的应用程序不同。

2)在此期间完成了什么,以及如何做。



一个问题是,您不能只更改文本,在代码中执行其他操作并再次更改文本,因为在代码完成之前,第一个文本将不会显示给用户 - 此时您已经改变了,所以他没有时间看第一条消息!



所以在Winforms应用程序中,你真的需要开始考虑多线程来移动关闭主UI线程的长执行代码,以便显示保持响应 - 如果你在UI线程中执行它,那么直到线程再次空闲才能处理UI事件。



在基于Web的应用程序中,情况更糟,因为显示的HTML不仅仅是在您进行微小更改时直接发送给客户端 - 它等到您完成构建表单之后。所以这也没有显示出来,以后更改它或者在Javascript中完成所有操作会更加麻烦。



所以停下来,想想你的任务,并准确地解决你想要做的事情。然后问我们,但请告诉我们尝试回答您的问题所需的所有信息。
Yes, you can do it...but exactly how depends on a lot of factors.
1) Environment. The methods for a web-based app are different to a Windows based app.
2) Exactly what is being done in the meantime, and how.

One problem is that you can't just change the text, do something else in code and change the text again, because the first text won't be displayed to the user until the code is complete - by which time you have changed it again, so he never gets time to see the first message!

So in a Winforms App, you really need to start looking at multithreading to "move" the long execution code off the main UI thread so that the display remains responsive - if you do it in the UI thread then no UI events can get processed until teh thread is free again.

In a web based app it's even worse, because the HTML for the display isn't just sent direct to the client when you make a tiny change - it waits until you are finished building the form. So that doesn't get displayed either, and there is even more hassle involved in changing it later, or doing it all in Javascript.

So stop, think about your task, and work out exactly what you are trying to do first. Then ask us, but give us all the information we need to try and answer your question.


这篇关于我可以一键更改按钮文本多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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