动态更改按钮 [英] Dynamic change of button

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

问题描述

我有一个名为start的按钮。现在,一旦我按下开始,应用程序运行正常..



我需要这样做:一旦应用程序到达特定点,它应该返回到前一个表单(第一个窗体,它有开始按钮)。现在按钮应该停止而不是开始。



我可以在C#windows应用程序中这样做吗?如果是这样,怎么样?



请帮我这个..



谢谢..

I have a button named start. Now once I press start, the application runs fine..

I need to do like this:once the application reaches a particular point it should return to the previous form(first form which is having start button).And there now the button should be stop instead of start.

Can I do like that in C# windows application?If so, how?

Please do help me on this..

Thanks..

推荐答案

这里有两个让你入门的选择



选项1:

保持开始按钮不变,将停止按钮放在旁边。您可以在每个上使用 Visible 属性来决定显示哪个属性(默认情况下,停止按钮应该将其设置为false)。您也可以使用已启用属性,禁用的按钮将显示为灰色。





选项2:

只需根据需要更改现有按钮的 Text 属性。如果您已将其命名为 btnStart ,请记得重命名该按钮。显然,你需要对额外的逻辑进行排序,以确定按钮是启动还是停止。一个快速入侵的方法就是使用按钮文本,尽管希望你的其余代码设计得足以使其不必要。





响应OP的评论:假设按钮被称为 btnStart ,例如,在代码中你执行以下操作:



Here are two options to get you started

Option 1:
Keep the start button as is, place the Stop button next to it. You can use the Visible property on each to decide which is displayed (the stop button should have this as false by default). You could alternatively use the Enabled property, the disabled button will appear greyed out.


Option 2:
Just change the Text property of the existing button as required. Remember to rename the button if you have called it btnStart. Obviously you'll need to sort the extra logic to determine whether the button is Starting or Stopping. A quick hack approach would be to even use the button Text, though hopefully the rest of your code is well enough designed to make this unnecessary.


In response to OP's comment: Assuming the button is called btnStart for example, in code you do the following:

btnStart.Visible = true; //To display, false to hide obviously





至于隐藏停止按钮,请在Visual Studio的设计器窗口中单击它。在属性选项卡中,在列表中找到可见属性,并将值设置为false。如果您在查找属性选项卡时遇到问题,请右键单击该按钮并选择属性,该选项卡将在默认设置中停靠在右侧。



As for hiding the Stop button, click on it in the designer window in Visual Studio. In the properties tab, find the "Visible" property in the list and set the value to false in that. If you are having problems finding the property tab, right click the button and choose "Properties", the tab is docked to the right on a default setup.


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

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