窗体浮动
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 联系我,非常感谢。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构