简体   繁体   English

我试图在单击时更改按钮的前景色,再次单击时它将恢复为原始颜色

[英]I am trying to make a buttons forecolor change when clicked and when it is clicked again it will revert back to its original color

I am trying to make a buttons forecolor change when clicked and when it is clicked again it will revert back to its original color and it loops that.我试图在单击时更改按钮的前景色,再次单击时它将恢复为原始颜色并循环播放。 Basically like a toggle that changes the color of a button when clicked and when clicked again reverts it to its original color.基本上就像一个切换按钮,在单击时更改按钮的颜色,再次单击时将其恢复为原始颜色。 I am doing this in c# and I have searched Multiple forums for an answer to this and no one has this specific problem so I am asking if you can please help me with the code.我在 c# 中这样做,我已经在多个论坛上搜索了这个问题的答案,但没有人遇到这个具体问题,所以我想问你是否可以帮我处理代码。 I have no code now because I do not know what to start with and ive tried multiple different things that havent worked.我现在没有代码,因为我不知道从什么开始,我尝试了多种不同的方法,但都没有用。

I have tried to have the buttons forecolor change when clicked which is easy but then reverting it back is hard and then looping it is something i cant seem to get working right now.我曾尝试在单击时更改按钮的前景色,这很容易,但随后将其恢复原状却很困难,然后循环播放是我现在似乎无法正常工作的事情。 None of my code works so I just request if it is possible a kind forum member can assist me with my code or provide me with code i need.我的代码都不起作用,所以我只是请求是否有好心的论坛成员可以帮助我处理我的代码或向我提供我需要的代码。 Thank You.谢谢你。

Well, it's not that hard.好吧,这并不难。 Just write something like that in action you want:只需在您想要的操作中写下类似的内容:

if (button1.ForeColor != Color.Green)
 {
   button1.ForeColor = Color.Green;
 }
 else
  {
   button1.ForeColor = Color.Red;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM