惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
博客园 - Franky
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
腾讯CDC
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
P
Privacy International News Feed
The Cloudflare Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
S
SegmentFault 最新的问题
美团技术团队
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
Cisco Talos Blog
Cisco Talos Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Cisco Blogs
NISL@THU
NISL@THU
J
Java Code Geeks
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
K
Kaspersky official blog
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
I
Intezer
U
Unit 42
博客园 - 聂微东
C
Check Point Blog
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
Latest news
Latest news
博客园 - 司徒正美
G
GRAHAM CLULEY
S
Schneier on Security
V
Visual Studio Blog

博客园 - 夜帝

无进程木马 思路 [转] DateTime 日期操作 C#开发终端式短信的原理和方法 JavaScript实现功能全集 全国网络广播电台地址 转 C#调用Windows API函数 AJAX基础教程 C#一个显示分页页码类 C#实现窗体淡入淡出效果的几种方法 如何用C#语言构造蜘蛛程序 - 夜帝 - 博客园 C#冒泡排序算法 创建不规则窗体和控件 初识C#线程 JavaScript中文版(入门) C#日期函数所有样式大全 C#中的“装箱”(boxing)与“拆箱”(unboxing) .net 中随机数的产生 使用C#开发COM+组件 C#算法 -- (三)希尔排序
用Visual C#编写仿MSN Messager的滚动提示窗口
夜帝 · 2007-09-14 · via 博客园 - 夜帝

第一步,建立一个Windows Application,然后在主form中放置一个Button

第二步,给这个Application添加一个窗体(Form2),把窗体的FormBorderStyle属性设置为None(无边框模式),然后把TopMost属性(总在最上方)属性设置为True,把ShowInTaskbar属性(是否在 Windows 任务栏中显示窗体)设置为False,并在窗体上加上你打算要显示的文字(实际应用中一般是在程序中动态加载),将窗体的背景设置为你想要的图片和合适的大小。最后再放上三个Timer控件,其中,timer1控制窗体滚出的动画,timer2控制窗体停留时间,timer3控制窗体的滚入动画,将它们的Interval属性设置为10。

第三步,编写代码,在Form2中添加两个属性用来设置窗体的显示大小:

private int heightMax, widthMax;
public int HeightMax
{
set
{
heightMax = value;
}
get
{
return heightMax;
}
}
public int WidthMax
{
set
{
widthMax = value;
}
get
{
return widthMax;
}
}

添加一个ScrollShow的公共方法:

public void ScrollShow()
{
this.Width = widthMax;
this.Height = 0;
this.Show();
this.timer1.Enabled = true;
}

添加一个StayTime属性设置窗体停留时间(默认为5秒):

public int StayTime = 5000;

添加ScrollUp和ScrollDown方法来编写窗体如何滚出和滚入:

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;
}
}
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();
}
}

在三个Timer的Tick方法中分别写入:

private void timer1_Tick(object sender, System.EventArgs e)
{
ScrollUp();
}
private void timer2_Tick(object sender, System.EventArgs e)
{
timer2.Enabled = false;
timer3.Enabled = true;
}
private void timer3_Tick(object sender, System.EventArgs e)
{
ScrollDown();
}

在Form2的Load事件中初始化窗体变量:

private void Form2_Load(object sender, System.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;
}

好了,滚动窗体的代码编写到这里就完成了,当然,它本身只实现了一个比较简单的窗体滚动滚出效果,具体如何去应用还应该配合你的程序来完成。当然,你还可以为它添加更多的功能,比如从窗体的任意位置显示(这里只是从右下角显示),淡入淡出效果,加上声音等等。最常用的就是写一个托盘程序,然后采用这种提醒效果。如何用C#编写托盘程序请参见:用Visual C#做托盘程序http://www.yesky.com/20020110/213425.shtml   最后,我们再回到Form1,在Button的Click事件中写如下代码来测试一下效果:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 form = new Form2();
form.HeightMax = 120;//窗体滚动的高度
form.WidthMax = 148;//窗体滚动的宽度
form.ScrollShow();
}

编译并运行程序,点击按纽,跟MSN Messager的效果一样。