Jie

心若无尘,一花一世界,一鸟一天堂;心若静,已如涅磐,风声物语,皆可成言.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Winform 启动时的渐入渐出效果

Posted on 2008-05-27 19:55  JieNet  阅读(885)  评论(0编辑  收藏  举报
两个form:
    frmLogo,logo窗口,启动时渐入渐出。
    MainForm,程序的主窗口。

frmLogo.Designer.cs 部分代码
//frmLogo.Designer.cs 部分代码

namespace FormTransparentEffectAtStart_up
{
        
//省略部分不重要的代码

      
/// <summary>
        
/// Required method for Designer support - do not modify
        
/// the contents of this method with the code editor.
        
/// </summary>

        private void InitializeComponent()
        
{
            
this.components = new System.ComponentModel.Container();
            
this.label1 = new System.Windows.Forms.Label();
            
this.timer1 = new System.Windows.Forms.Timer(this.components);
            
this.SuspendLayout();
            
// 
            
// label1
            
// 
            this.label1.AutoSize = true;
            
this.label1.BackColor = System.Drawing.Color.Silver;
            
this.label1.Font = new System.Drawing.Font("华文新魏", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            
this.label1.ForeColor = System.Drawing.Color.Black;
            
this.label1.Location = new System.Drawing.Point(7047);
            
this.label1.Name = "label1";
            
this.label1.Size = new System.Drawing.Size(29721);
            
this.label1.TabIndex = 0;
            
this.label1.Text = "FormTransparentEffectAtStart-up";
            
// 
            
// timer1
            
// 
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            
// 
            
// FrmLogo
            
// 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
            
this.ClientSize = new System.Drawing.Size(438114);
            
this.Controls.Add(this.label1);
            
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            
this.MaximizeBox = false;
            
this.MinimizeBox = false;
            
this.Name = "FrmLogo";
            
this.Opacity = 0;
            
this.ShowIcon = false;
            
this.ShowInTaskbar = false;
            
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            
this.Text = "FrmLogo";
            
this.ResumeLayout(false);
            
this.PerformLayout();

        }


        
#endregion

        
private System.Windows.Forms.Label label1;
        
private System.Windows.Forms.Timer timer1;
    }

}


//frmLogo.cs 代码
//frmLogo.cs 代码

namespace FormTransparentEffectAtStart_up
{
    
public partial class FrmLogo : Form
    
{
        
public FrmLogo()
        
{
            InitializeComponent();

            
this.Opacity = 0;//透明度 设置为0

            
this.timer1.Enabled = true;
            
this.timer1.Interval = 150;//触发时间为150ms
        }


        
bool bSubtractAlpha = true;//减少透明度
        bool bAddAlpha = false;//增加透明度

        
private void timer1_Tick(object sender, EventArgs e)
        
{
            
            
//逐渐减少透明度
            if (bSubtractAlpha)
            
{
                
if (this.Opacity < 1)
                
{
                    
this.Opacity += 0.1;
                }

                
else
                
{
                    bSubtractAlpha 
= false;
                    bAddAlpha 
= true;
                }

            }


            
//逐渐增加透明度
            if (bAddAlpha)
            
{
                
if (this.Opacity > 0.1)
                
{
                    
this.Opacity -= 0.1;
                }

                
else
                
{
                    bAddAlpha 
= false;
                    
this.timer1.Enabled = false;
                }

            }


            
//启动主窗口
            if (this.timer1.Enabled == false)
            
{
                
new MainForm().Show();
            }


        }

    }

}



//MainForm.cs 代码
//MainForm.cs 代码
namespace FormTransparentEffectAtStart_up
{
    
public partial class MainForm : Form
    
{
        
public MainForm()
        
{
            InitializeComponent();
        }


        
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        
{
            
//关闭所有
            Application.ExitThread();
        }

    }

}