窗体浮动
1 private void Form1_Load(object sender, EventArgs e)
2 {
3
4 }
5 private int screenWidth;//屏幕宽度
6 private int screenHeight;//屏幕高度
7 private bool isUp = true;//是否完全显示提示窗口
8
9 public void init()
10 {
11 screenHeight = Screen.PrimaryScreen.Bounds.Height;
12 screenWidth = Screen.PrimaryScreen.Bounds.Width;
13 //设置提示窗口坐标在屏幕可显示区域之外
14 Location = new Point(screenWidth - Width, screenHeight);
15 StartPosition = FormStartPosition.Manual;
16 timer1.Start();
17 textBox1.Text = "";
18 //Class1.sendEvent += new Class1.SendMessage(this.DoMethod);
19
20 }
21 private void timer1_Tick(object sender, EventArgs e)
22 {
23 if (isUp)//如果提示窗口没有完全显示
24 {
25 if (Location.Y > 0)
26 {
27 Location = new Point(Location.X, Location.Y - 5);
28 }
29 else
30 {
31 isUp = false;
32 }
33 ////如果提示窗口的纵坐标与提示窗口的高度之和大于屏幕高度
34 //if (Location.Y + Height >= screenHeight)
35 //{
36 // Location = new Point(Location.X, Location.Y - 5);
37 //}
38 //else
39 //{
40 // // timer1.Stop();
41 //}
42 }
43 else//如果提示窗口已经完成了显示,并且点击了确定按钮
44 {
45 //如果提示窗口没有完全从屏幕上消失
46 if (Location.Y+Height < screenHeight)
47 {
48 Location = new Point(Location.X, Location.Y + 5);
49 }
50 else
51 {
52 isUp = true;
53 }
54 }
55 }
56
57 private void Form1_MouseEnter(object sender, EventArgs e)
58 {
59 timer1.Stop();
60 }
61
62 private void Form1_MouseLeave(object sender, EventArgs e)
63 {
64 timer1.Start();
65 }
66
67 private void button1_Click(object sender, EventArgs e)
68 {
69 this.Dispose();
70 this.Close();
71 }
72
73 private void button1_MouseEnter(object sender, EventArgs e)
74 {
75 timer1.Stop();
76 }
77 public void DoMethod(string getstr)
78 {
79 textBox1.Text += getstr;
80 }
81
82 private void textBox1_MouseEnter(object sender, EventArgs e)
83 {
84 timer1.Stop();
85 }
作者:唐小熊
出处:http://www.cnblogs.com/IT-Bear/
关于作者:一头写代码的熊
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接
如有问题,可以通过kumat@foxmail.com 联系我,非常感谢。