C# 在窗口右下角弹出广告的代码,渐变显示与自动消失

发布时间:2009年07月10日      浏览次数:2205 次
绝对的原创,呵呵,欢迎转载
转载请注明作者相关信息:
------------------------------------------
文章来自:桂林唯创网络 http://www.93cn.net
作者:Leo
邮箱:admin_8@126.com
------------------------------------------
[ 代码如下 ]:
在窗体里需要添加一个timer控件,在此命名为timer1,并在timer控制的Tick事件中写入timer1_Tick的相关代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MySoft
{
public partial class Msg_form : Form
{
private bool display = true; //定义窗体是显示(true)还是消失(false)
private int S_width = 0; //定义屏幕宽度
private int S_height = 0; //定义屏幕高度
private double count = 0; //定义一个用于延时的计数器
public Msg_form()
{
InitializeComponent();

//指定窗体显示位置
Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
S_width = ScreenArea.Width; //获取屏幕宽度
S_height = ScreenArea.Height; //获取屏幕高度
//控制窗体渐变出现效果
this.timer1.Enabled = true;//获取当前运行时间
this.Opacity = 0.0;//获取当前窗体的透明度级别;
}
//窗体渐变出现效果
private void timer1_Tick(object sender, EventArgs e)
{
if (display)
{
if (this.Opacity < 1)
{
this.Opacity = this.Opacity + 0.1;//窗体以0.1的速度渐变显示
}
else
{
count = count + 0.1;
if ( count >= 5 ) display = false; //当完全显示后,延时5秒自动渐变消失
}
}
else
{
if (this.Opacity > 0)
{
this.Opacity = this.Opacity - 0.1;//窗体以0.1的速度渐变消失
}
else
{
this.timer1.Enabled = false;//时间为false
Close();//关闭窗体
}
}
if (this.Opacity <= 1)
{
//指定窗体显示在右下角
this.Location = new System.Drawing.Point(S_width - 300, S_height - Convert.ToInt32(160 * this.Opacity));
}
}
}
}
文章来源:桂林唯创网络
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!