Windows Form 实现透明效果,渐变效果,淡入淡出效果的实现

在用到vs 2005的兴奋过程中,想给程序做个启动画面,我采用了显示Aform,过一段时间,隐藏这个Aform,showdialog下一个Bform,closeAForm这个方法来做了,不知道大家有没有跟好的办法。

设定程序丛Aform启动:
         static   void  Main()
        
dot.gif {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(
false);
            Application.Run(
new Aform());
        }


我在AForm中定义如下timer
%7BF6FEED5D-4A51-4989-ACD7-8A24D3020FE2%7D.JPG

定义了他们的属性
 StartWindowShowTime(显示Aform的时间长度)
Enabled=True
Interval=5000 (100=1秒)

HideWindowStart (开始隐藏Aform的过程)
Enabled=True
Interval=4500

HideWindowSpeed (隐藏Aform的渐变间隔)
Enabled=False
Interval=10

ShowWindowStart  (显示AForm的渐变间隔)
Enabled=True
Interval=10

Ok,   下面开始定义这些timer的Tick
在Events里面可以直接填写,timer就这一个,也可以后台写,不过我觉得在这里填写比较方便,而且可以自动生成方法的声明,不用找了。偷懒一下。

StartWindowShowTime
Tick:ShowMainwindow

HideWindowStart
Tick:HideWindow

HideWindowSpeed
Tick:HideWindowSpeedStart

ShowWindowStart
Tick:ShowWindow

好了,到这里我要说Windows Form 实现透明效果,渐变效果,淡入淡出效果的实现最重要一员了,那就是Form属性里的Opacity,用的就是这个。我考证过,只有2000以上的系统支持这个属性。

 我们先将Aform的Opacity设置成0,好了开始写Aform的代码

     public  partial  class  Aform: Form
    
dot.gif {
        
public Form()
        
dot.gif{
            InitializeComponent(); 
            

            
        }


        
private void Start_Load(object sender, EventArgs e)
        
dot.gif{
            StartWindowShowTime.Start();
            HideWindowStart.Start();
        }


        
private void ShowMainwindow(object sender, EventArgs e)
        
dot.gif{
            Bform showmainwindows 
= new Bform();            
            
this.Hide();
            StartWindowShowTime.Stop();
            HideWindowStart.Stop();
            HideWindowSpeed.Stop();
            showmainwindows.ShowDialog();
            
this.Close();
        }


        
private void HideWindow(object sender, EventArgs e)
        
dot.gif{
            HideWindowSpeed.Start();
        }


        
private void HideWindowSpeedStart(object sender, EventArgs e)
        
dot.gif{
            
this.Opacity = this.Opacity - 0.02;
        }


        
private void ShowWindow(object sender, EventArgs e)
        
dot.gif{
            
if (this.Opacity == 1)
            
dot.gif{
                ShowWindowStart.Stop();
            }

            
else
            
dot.gif{
                
this.Opacity = this.Opacity + 0.02;
            }

        }


    }

好了,这个时候大家运行看看,嘿嘿淡入淡出。

我本来把Opacity每次更改的数值设置成了0.1,可是发现如果那样的话淡入淡出不是很润,所以缩小了数值和间隔时间。这样看起来就润多了。自我感觉不错。

如果大家的程序只需要透明,那么只用设置Opacity这个就可以了。

渐变和淡入淡出照猫画虎用timer和Opacity这个配合一下,就可以做出来了。

小心得,和大家分享一下。很希望和大家交个朋友。

大家记得联系我啊!

大胆一下,把文章发到首页了!怕怕!
 

转载于:https://www.cnblogs.com/tishifu/archive/2005/11/26/284948.html

你可能感兴趣的:(Windows Form 实现透明效果,渐变效果,淡入淡出效果的实现)