简体   繁体   中英

Changing form color depending on answer

I have searched, and tried answers. I have the code, but I'm unsure why it isn't working. I am trying to change the backcolor of the form from green back to white. I believe I have it correct, but it doesn't show the first color, only the last.

 if (PassBox1.Text == PassBox2.Text)
 {
     this.BackColor = Color.FromArgb(0, 255, 0);

     // voice.Speak("Correct ", SpeechVoiceSpeakFlags.SVSFDefault);

     this.BackColor = Color.FromArgb(192,192,192);
 }

When this code runs and backcolor is set to (0,255,0) which is followed by a blocking operation voice.speak, this does not give chance to the ui to refresh and soon as voice speak is done, the backcolor changes to (192...) before ui gets changes to show the other color.

in this case you would be much happier if you created a subclassed text box which allows you to flash colors. you can use some ideas from this post https://stackoverflow.com/a/4147406/2903863

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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