自动提醒功能

来源:互联网 发布:机房网络布线施工报价 编辑:程序博客网 时间:2024/04/30 15:11

用FORM实现

C# code
实现类似MSN好友上线的提示设置两个窗体:form2(即好友上线提示的容器) :代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace MSN{ public partial class Form2 : Form { public Form2() { InitializeComponent(); } private int heightMax, widthMax; public int HeightMax { set { heightMax = value; } get { return heightMax; } } public int WidthMax { set { widthMax = value; } get { return widthMax; } } //Timer1控制窗体滚出的动画,timer2控制窗体停留时间,timer3控制窗体的滚入动画 public void ScrollShow() { this.Width = widthMax; this.Height = 0; this.Show(); this.timer1.Enabled = true; } public int StayTime = 5000; int a = 30; private void ScrollUp() { if (Height < heightMax) { this.Height += 3; this.Location = new Point(this.Location.X, this.Location.Y - 3); } else { this.timer1.Enabled = false; this.timer2.Enabled = true; } //if (a <= heightMax * 8 ) //{ // a += 3; // this.Height = 35 ; // this.Location = new Point(this.Location.X, this.Location.Y - 3); // if(this.Location.X > 500 ) // { // this.Location = new Point(this.Location.X - 3, this.Location.Y); // } //} } private void ScrollDown() { if (Height > 3) { this.Height -= 3; this.Location = new Point(this.Location.X, this.Location.Y + 3); } else { this.timer3.Enabled = false; this.Close(); } } private void timer3_Tick(object sender, EventArgs e) { ScrollDown(); } private void timer1_Tick(object sender, EventArgs e) { ScrollUp(); } private void timer2_Tick(object sender, EventArgs e) { timer2.Enabled = false; timer3.Enabled = true; } private void Form2_Load(object sender, EventArgs e) { Screen[] screens = Screen.AllScreens; Screen screen = screens[0];//获取屏幕变量 this.Location = new Point(screen.WorkingArea.Width - widthMax - 20, screen.WorkingArea.Height - 34); //WorkingArea为Windows桌面的工作区 this.timer2.Interval = StayTime; } }}form1 前台的调用 :代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace MSN{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Screen[] screens = Screen.AllScreens; Screen screen = screens[0];//获取屏幕变量 Form2 form = new Form2(); form.HeightMax = 120;//窗体滚动的高度 form.WidthMax = 148;//窗体滚动的宽度 form.ScrollShow(); } }}