When setting a form's opacity should I use a decimal or double?
I want to use a track-bar to change a form’s opacity.
This is my code:
decimal trans = trackBar1.Value / 5000; this.Opacity = trans;
When I try to build it, I get this error:
Cannot implicitly convert type ‘decimal’ to ‘double’.
I tried making
double, but then the control doesn’t work. This code has worked fine for me in VB.NET in the past.
The Opacity property is of double type:
double trans = trackBar1.Value / 5000.0; this.Opacity = trans;
this.Opacity = trackBar1.Value / 5000.0;
this.Opacity = trackBar1.Value / 5000d;
Notice that I am using
5000d) to force a double division because
trackBar1.Value is an integer and it would perform an integer division and the result would be an integer.