做了一给用户控件

1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Text;
  7 using System.Windows.Forms;
  8 
  9 namespace MSNMessageForm
 10 {
 11     public partial class TestSmallWindow : Form
 12     {
 13         private int heightMax, widthMax;
 14         public int StayTime = 3000;//窗体停留时间(默认为5秒)
 15         //定义窗体大小
 16         public int HeightMax
 17         {
 18             set
 19             {
 20                 heightMax = value;
 21             }
 22             get
 23             {
 24                 return heightMax;
 25             }
 26         }
 27 
 28         public int WidthMax
 29         {
 30             set
 31             {
 32                 widthMax = value;
 33             }
 34             get
 35             {
 36                 return widthMax;
 37             }
 38         }
 39         public TestSmallWindow()
 40         {
 41             InitializeComponent();
 42         }
 43 
 44         private void button1_Click(object sender, EventArgs e)
 45         {
 46             this.Close();
 47         }
 48 
 49         private void TestSmallWindow_Load(object sender, EventArgs e)
 50         {
 51             Screen[] screens = Screen.AllScreens;
 52             Screen screen = screens[0];//获取屏幕变量
 53             this.Location = new Point(screen.WorkingArea.Width - widthMax - this.Width, screen.WorkingArea.Height - this.Height);
 54             //WorkingArea为Windows桌面的工作区
 55             this.timer2.Interval = StayTime;
 56         }
 57 
 58         public void ScrollShow()
 59         {
 60             this.Height = 0;
 61             this.Show();
 62             this.timer1.Enabled = true;
 63         }
 64         private void ScrollUp()
 65         {
 66             if (Height < heightMax)
 67             {
 68                 this.Height += 3;
 69                 this.Location = new Point(this.Location.X, this.Location.Y - 3);
 70             }
 71             else
 72             {
 73                 this.timer1.Enabled = false;
 74                 this.timer2.Enabled = true;
 75             }
 76         }
 77 
 78         private void ScrollDown()
 79         {
 80             if (Height > 3)
 81             {
 82                 this.Height -= 3;
 83                 this.Location = new Point(this.Location.X, this.Location.Y + 3);
 84             }
 85             else
 86             {
 87                 this.timer3.Enabled = false;
 88                 this.Close();
 89             }
 90         }
 91 
 92         private void timer3_Tick(object sender, EventArgs e)//设置由上向下自动消失窗体
 93         {
 94             ScrollDown();
 95         }
 96 
 97         private void timer2_Tick(object sender, EventArgs e)//
 98         {
 99             timer2.Enabled = false;
100             timer3.Enabled = true;
101         }
102 
103         private void timer1_Tick(object sender, EventArgs e)//此处设置由下向上弹出我们制造的窗体
104         {
105             ScrollUp();
106         }
107     }
108 }

 

程序调用

 

1 private void btnTest_Click(object sender, EventArgs e)
2 {
3   TestSmallWindow form = new TestSmallWindow();
4   form.HeightMax = 120;//窗体滚动的高度
5   form.WidthMax = 148;//窗体滚动的宽度
6   form.ScrollShow();
7 }

效果图

 

posted on 2010-08-21 13:59  kjunmine  阅读(1954)  评论(0编辑  收藏  举报