C# 窗体缓缓上升与下降
2013-10-11 09:25
169 查看
using System; using System.Windows.Forms; namespace Calc { public partial class FloatForm : Form { public FloatForm() { InitializeComponent(); } private void FloatForm_Load(object sender, EventArgs e) { this.Width = 400; this.Height = 300; this.TopMost = true; this.Opacity = 0.5; //初始化窗口到屏幕右下角 this.Top = Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height; this.Left = Screen.PrimaryScreen.WorkingArea.Left + Screen.PrimaryScreen.WorkingArea.Width - this.Width; } private void FloatForm_Shown(object sender, EventArgs e) { this.timer1.Interval = 10; this.timer1.Tick += new EventHandler(timer1_Tick); this.timer1.Start(); } void timer1_Tick(object sender, EventArgs e) { if (this.Top + this.Height/2> Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height/2) { this.Top -= 2; //每次移动2个像素,可修改 this.Opacity += 0.002; Application.DoEvents(); } else { this.timer1.Stop(); this.Opacity = 1; } } private void FloatForm_FormClosing(object sender, FormClosingEventArgs e) { if (this.Tag != null && (int)this.Tag == 100) { e.Cancel = false; return; } e.Cancel = true; if (this.timer1.Enabled) return; //如果是在关闭进程中,不处理 this.timer1.Tick -= timer1_Tick; this.timer1.Tick += new EventHandler(timer1_Tick2); this.timer1.Start(); } void timer1_Tick2(object sender, EventArgs e) { if (this.Top < Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height) { this.Top += 2; //每次移动2个像素,可修改 this.Opacity -= 0.002; Application.DoEvents(); } else { this.timer1.Stop(); this.Tag = 100; this.Close(); } } } }
相关文章推荐
- 市场份额C#稳步上升,Java稳步下降
- [转摘]VB用户下降,C/C++/C#用户上升
- c# 窗体 显示居中 wince
- C#无边框窗体的拖动
- C#中winform窗体如何嵌入cmd命令窗口
- 1065: 合唱队形(最长上升,下降子序列)
- C# WinForm窗体及其控件的自适应
- c# 隐藏主窗体
- C# 多线程 异步加载 窗体
- C#winform中打开PDF文件并在窗体中显示
- 简易记事本---C#窗体
- C# WINFORM 强制让窗体获得焦点(可实现单次置顶或持续置顶)
- C# 委托实例(跨窗体操作控件)
- C#制作闪动的窗体
- C# 第一个窗体的数据传递到第二个窗体上应用
- 用C#实现不规则窗体
- C#创建不规则窗体的4种方式详解
- C# FORM中创建圆形窗体 + 移动窗体
- C# WinForm 在窗口菜单上显示已打开窗体的标题及其窗体的排列
- C#按钮在窗体居中