# 在将不透明度应用于表单时，我们应该使用小数还是双精度值？

``````decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;
``````

0

## 13 答案

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

``````double trans = trackBar1.Value / 5000.0;
double trans = trackBar1.Value / 5000d;
``````
1

0

0

``````// Example 1
double transperancy = trackBar1.Value/5000;
this.Opacity = decimal.ToDouble(transperancy);

// Example 2 - with inline temp
this.Opacity = decimal.ToDouble(trackBar1.Value/5000);
``````
0

``````trackBar.Opacity = (double)trackBar.Value / 5000.0;
``````
0

``````decimal trans = trackBar1.Value / 5000m;
this.Opacity = (double) trans;
``````

0

``````this.Opacity = decimal.ToDouble(trackBar1.Value/5000);
``````
0

0

``````private void Form1_Load(object sender, System.EventArgs e)
{
TrackBar1.Minimum = 20;
TrackBar1.Maximum = 100;

TrackBar1.LargeChange = 10;
TrackBar1.SmallChange = 1;
TrackBar1.TickFrequency = 5;
}

private void TrackBar1_Scroll(object sender, System.EventArgs e)
{
this.Opacity = TrackBar1.Value / 100;
}
``````
0

Opacity 属性是双重类型：

``````double trans = trackBar1.Value / 5000.0;
this.Opacity = trans;
``````

``````this.Opacity = trackBar1.Value / 5000.0;
``````

``````this.Opacity = trackBar1.Value / 5000d;
``````

0

``````double trans = trackBar1.Value / 5000.0;
this.Opacity = trans;
``````

``````this.Opacity = trackBar1.Value / 5000.0;
``````

``````double trans = trackbar1.Value / 5000;
``````

0

``````Opacity = trackBar1.Value / 5000.0;
``````
0

``````this.Opacity = trackBar1.Value / 5000d;
``````
0