Bill English <an*******@discussions.microsoft.com> wrote:
I'm new to C#, and I want to use a trackbar for the forms 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 trans a double, but then the control doesn't work.
What do you mean by "doesn't work"? In what way doesn't it work?
You can always cast from decimal to double - in other words explicitly
converting rather than trying to implicitly convert.
This code worked fine for me in VB.NET. Any suggestions?
Did you have option strict on in VB.NET? If not, I suggest you have it
on in future, to give you more type safety. If so, I'm surprised it
worked. (Then again, I'm no VB.NET expert. Maybe it's happy to do
potentially dodgy conversions for you implicitly.)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too