C# TrackBar 控件调节 窗体透明度及颜色渐变

一。窗体透明度

首先拖控件到窗体.然后在TrackBar 控件Scroll 事件中,

代码如下:

this.Opacity = (100 - trackBar1.Value) / 100.0;

这个窗体的透明度=100-控件游标所处的位置值除以100.0,目的就是为了得到0-1.0之间的数.

窗体透明度属性,取值范围是 0-1.0,

将 TrackBar 的 Maximum 设为 100,设置:游标的可移动最多多少个"格子",想象一下刻度尺.

将 TrackBar 的 TickFrequency 设为 10,这个设置每次移动最少几个格子.

 

二。窗体颜色渐变

       private void trackBar1_Scroll(object sender, EventArgs e)
        {    
            this.Opacity = (100 - trackBar1.Value) / 100.0;
           

        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            Color StyleColor = Color.FromArgb(255, trackBar2.Value, trackBar3.Value, trackBar4.Value);

              this.BackColor = StyleColor;

        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            Color StyleColor = Color.FromArgb(255, trackBar2.Value, trackBar3.Value, trackBar4.Value);

              this.BackColor = StyleColor;
        }

        private void trackBar4_Scroll(object sender, EventArgs e)
        {
            Color StyleColor = Color.FromArgb(255, trackBar2.Value, trackBar3.Value, trackBar4.Value);

              this.BackColor = StyleColor;
        }

你可能感兴趣的:(技术)