So, firstly, application.DoEvents should be avoided if you really donโt know what you are doing and are sure that this is an appropriate use and that you are using it correctly. I am absolutely sure that this is not so.
Then, how do you control the speed of fading? You basically just let the computer fade as fast as you can, and rely on the overhead of operations (and background processes) to make this take more time. This is really not a good design. Youโd better clarify how long it takes to fade out from the start so that it is consistent between machines. You can use Timer to execute the code at appropriate intervals and make sure that the user interface thread is not blocked for the time of fading (without using DoEvents ).
Just change the duration below to change how long the fade takes and change the steps to determine how โfadingโ it is. I have 100 installed because it is effectively what your code did before. In fact, you probably don't need a lot, and you can just go down before you start to hesitate. (The lower the steps, the better it will be.)
Plus, you shouldn't worry so much about performance for something like that. Attenuation is something that needs to be measured on a scale of about a second or not much less (so that a person can perceive it), and for any computer these days it can do it, much more than this per second is not even funny. It will consume almost no processor in terms of computing within a second, so an attempt to optimize it will certainly be micro-optimization.
private void button1_Click(object sender, EventArgs e) { int duration = 1000;
Servy
source share