You have two problems.
Firstly, Opacity
requires a double, not a decimal value. The compiler is telling you that while there is a conversion between decimal and double, it is an explicit conversion that you need to specify in order for it to work.
Secondly, TrackBar.Value
is an integer value and dividing an int by an int results in an int no matter what type of variable you assign it to. In this case there is an implicit cast from int to decimal or double, because there is no loss of precision when you do the cast. So the compiler doesn't complain. But the value you get is always 0, presumably, since trackBar.Value
is always less than 5000.
The solution is to change your code to use double (the native type for Opacity) and do floating point arithmetic by explicitly making the constant a double, which will have the effect of promoting the arithmetic or casting trackBar.Value
to double, which will do the same thing or both. You don't need the intermediate variable unless it is used elsewhere. My guess is the compiler would optimize it away anyway.
trackBar.Opacity = (double)trackBar.Value / 5000.0;
trackbar
. It is unlikely that it has ever been done to use such a high value ontrackbar
– Franck