I am trying to add a fade effect to my form by manually changing the opacity of the form, but I am having trouble calculating the correct value to increase the opacity of the form.
I know that I could use the AnimateWindow API, but it showed some unexpected behavior, and I would prefer to do it manually anyway, to avoid any p / invoke, so I can use it in Mono later.
My application supports speeds from 1 to 10. And I manually calculated that for speed 1 (the slowest) I should increase the opacity by 0.005 and for speed 10 (faster) I should increase by 0.1. As for speeds from 1 to 10, I used the following expression to calculate the correct value:
double opSpeed = (((0.1 - 0.005) * (10 - X)) / (1 - 10)) + 0.1;
Although it can give me a linear meaning and that everything will be alright. However, for X equal to 4 and above, this is already too fast. More than it should be. I mean, the speed is from 7 to 10, I can hardly see the difference, and the speed of the animation with these values ββshould be a little more spaced.
Please note that I still want the fastest growth of 0.1 and the slowest 0.005. But I need everyone else to be linear between them.
What am I doing wrong?
EDIT: It actually makes sense why this works, for example, for a fixed interval between increments, say, a few milliseconds and with the above equation, if X = 10, then opSpeed ββ= 0.1, and if X = 5, then opSpeed = 0.47. If we think about it, the value 0.1 will depend 10 times, and the value 0.47 will loop on the double. For such a small interval of just a few milliseconds, the difference between these values ββis not so much that they differentiate speeds from 5 to 10.