C# - When setting a form's opacity should I use a decimal or double?

I'm new to C#, and 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 trans a double, but then the control doesn't work. This code worked fine for me in VB.NET.

What do I need to do differently?

This question and answers originated from www.stackoverflow.com
Question by (7/31/2008 9:42:52 PM)

Answer

An explicit cast to double isn't necessary.

double trans = (double)trackBar1.Value / 5000.0;

Identifying the constant as 5000.0 (or as 5000d) is sufficient:

double trans = trackBar1.Value / 5000.0;
double trans = trackBar1.Value / 5000d;
Answer by

Find More Answers
Related Topics  c#  winforms  opacity
Related Questions
  • Windows Forms Opacity After Shown- C#

    I am tryig to fade-in a windows form using c# but it doesnt seem to work after I have shown the form. Is it possible to change the forms opacity after Ive shown it? Code: using System; using S…
  • C# 2 forms and opacity question

    I have 2 forms. on the second form i have a track bar. Whenever that track bar changes it's value, I want form 1 to become transparent. My code. opacitytrackBar1.ValueChanged += new EventHandler(…
  • place a form with Opacity over a main form with datagridview winform

    I have a form (named mainForm.cs) with a datagridview on it. I must to show a picture (with opacity) over a datagrdiview. To achieve this, I made another form (frmPicture) with a picturebox, and …
  • winforms opacity problem

    Hi I want to set opacity for a form in page load. I try to set the opacity like this this.Opacity = 10; in paage load but it is not working. May i know the reason
  • WinForm Control with Opacity

    I have a form that has some controls on itself(btnCreateReport,pnlDarkLayer).I have a panel that fit to form(Dock = Fill) and it is on the back of all controls.when user click on the btnCreateReport…
  • c# Form.Hide() vs. Form.Opacity = 0

    I was wondering if there are any gotchas for making a form completely transparent (as opposed to hiding it). For instance, I know that these are things that got my by surprise when hiding a form: …
  • Making a form be invisible when it first loads

    Currently, the form's opacity is 0%, so that when it loads, it should be invisible, but when the form loads, it's visible for a few seconds. Since the default opacity is set to 0% and the form's vis…
  • How can I set the opacity or transparency of a Panel in WinForms?

    I was wondering how to change or modify the transparency of a Panel in C#, not the whole form, but the panel only.. I've seen many C# tutorials on Opacity, but its for the Form. im looking for how i…
  • decimal vs double! - Which one should I use and when?

    I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type i…
  • When should I use double instead of decimal?

    I can name three advantages to using double (or float) instead of decimal: Uses less memory Faster because floating point math operations are natively supported by processors Can represent …