[CodeProject每日一荐] TaskbarNotifier: 可换肤的 MSN Messenger-like 风格窗体( C# & VB.NET)
来源:互联网 发布:c语言获取时间随机数 编辑:程序博客网 时间:2024/06/18 05:23
这是我昨天(今天凌晨)说到的今天要介绍的TaskbarNotifier, a skinnable MSN Messenger-like popup in C# and now in VB.NET too By John O'Byrne. 可惜昨天晚上写好的那篇文章,因为过了24:00,日期只能记在今天名下了,没找到博客园里改文章时间的地方:|
[介绍]
笔者在学习C#时移植自己C++的CTaskbarNotifier类,实现了这个可换肤的MSN Messenger-like 风格窗体, 在某种风格下看起来和MSN Messenger的弹出窗口很相像.
[特色]
支持:
1. 可定制的透明位图背景
2. 可换肤且有3种状态的关闭按钮
3. 可以点击的标题文本
4. 可以点击的内容文本
5. A selection rectangle
6. 可定制文本在不同状态(平常/鼠标悬停)下的字体,颜色
7. 有参数可控制动画移进移出的速度
[兼容性]
该类可独立运行,除.NET基础类库不需其他库.以托管代码编写,可移植性较好
[如何使用]
- 首先,复制TaskbarNotifier.cs到你的项目目录下.
- 在你的代码顶部加上: using CustomUIControls;
- 在你的类中加上一个成员变量: TaskbarNotifier taskbarNotifier;
- 在你的类构造函数中中加上: taskbarNotifier=new TaskbarNotifier();
taskbarNotifier.SetBackgroundBitmap("skin.bmp",
Color.FromArgb(255,0,255));
taskbarNotifier.SetCloseBitmap("close.bmp",
Color.FromArgb(255,0,255),new Point(127,8));
taskbarNotifier.TitleRectangle=new Rectangle(40,9,70,25);
taskbarNotifier.ContentRectangle=new Rectangle(8,41,133,68);
taskbarNotifier.TitleClick+=new EventHandler(TitleClick);
taskbarNotifier.ContentClick+=new EventHandler(ContentClick);
taskbarNotifier.CloseClick+=new EventHandler(CloseClick);
(译者:比较直观简单,略去介绍)最后一行表示窗体的弹出耗时500ms, 显示持续3000ms,消失耗时500ms.
[手册文档]
方法
void Hide();
void SetBackgroundBitmap(string strFilename, Color transparencyColor);
void SetBackgroundBitmap(Image image, Color transparencyColor);
void SetCloseBitmap(string strFilename, Color transparencyColor, Point position);
void SetCloseBitmap(Image image, Color transparencyColor, Point position);
属性
string ContentText (get/set)
TaskbarStates TaskbarState (get)
Color NormalTitleColor (get/set)
ColorHoverTitleColor (get/set)
Color NormalContentColor (get/set)
Color HoverContentColor (get/set)
Font NormalTitleFont (get/set)
Font HoverTitleFont (get/set)
Font NormalContentFont (get/set)
Font HoverContentFont (get/set)
Rectangle TitleRectangle (get/set)//must be defined before calling show())
Rectangle ContentRectangle (get/set)//must be defined before calling show())
bool TitleClickable (get/set) (default = false);
bool ContentClickable (get/set) (default = true);
bool CloseClickable (get/set) (default = true);
bool EnableSelectionRectangle (get/set) (default = true);
事件
event EventHandler TitleClick
event EventHandler ContentClick
[技术细节]
窗体的皮肤是通过给定图片和透明色来在一块区域中动态绘制实现的
{
if (bitmap == null)
throw new ArgumentNullException("Bitmap","Bitmap cannot be null!");
int height = bitmap.Height;
int width = bitmap.Width;
GraphicsPath path= new GraphicsPath();
for (int j=0; j<height; j++ )
for (int i=0; i<width; i++)
{
if (bitmap.GetPixel(i, j)== transparencyColor)
continue;
int x0 = i;
while ((i < width) &&
(bitmap.GetPixel(i, j)!= transparencyColor))
i++;
path.AddRectangle(new Rectangle(x0, j, i-x0,1));
}
Region region= new Region(path);
path.Dispose();
return region;
}
窗体的Refresh()使用了双缓冲技术避免闪烁
{
Graphics grfx= pea.Graphics;
grfx.PageUnit= GraphicsUnit.Pixel;
Graphics offScreenGraphics;
Bitmap offscreenBitmap;
offscreenBitmap= new Bitmap(BackgroundBitmap.Width,
BackgroundBitmap.Height);
offScreenGraphics= Graphics.FromImage(offscreenBitmap);
if (BackgroundBitmap!= null)
{
offScreenGraphics.DrawImage(BackgroundBitmap,
0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height);
}
DrawCloseButton(offScreenGraphics);
DrawText(offScreenGraphics);
grfx.DrawImage(offscreenBitmap,0, 0);
}
[Bug/限制]
为了只使用托管代码, 用了 Screen.GetWorkingArea(WorkAreaRectangle) 函数来取得任务栏位置,结果窗体总出现在WorkAreaRectangle的底部.
在C#托管代码中没找到 ShowWindow(SW_SHOWNOACTIVATE)
来让窗体出现但不抢走当前窗口焦点的方法.
http://www.codeproject.com/Articles/3285/TaskbarNotifier-a-skinnable-MSN-Messenger-like-pop
- [CodeProject每日一荐] TaskbarNotifier: 可换肤的 MSN Messenger-like 风格窗体( C# & VB.NET)
- TaskbarNotifier: 可换肤的 MSN Messenger-like 风格窗体( C# & VB.NET)
- NotifyWindow: 一个轻量级 MSN Messenger 风格的通知窗体
- C#实现类似MSN Messenger的弹出提示窗体
- MSN Messenger 协议分析一
- MSN Messenger 协议分析一
- ASP.NET 仿MSN Messenger Alert的弹出窗口控件
- ASP.NET 仿MSN Messenger Alert的弹出窗口控件
- MSN Style TaskbarNotifier【Winform Only】
- VB.NET之旅(一)—失踪的窗体
- MSN Messenger的用户管理
- 去除MSN Messenger的广告
- 用C#和VB.NET实现VS.NET或Office XP风格的菜单(一)
- 用C#和VB.NET实现VS.NET或Office XP风格的菜单(一)
- 用C#和VB.NET实现VS.NET或Office XP风格的菜单(一)
- 在.net(C# or vb.net)中如何取消一个窗体的关闭。
- C#模拟MSN窗体抖动
- C#模拟MSN窗体抖动
- ContentProvider, ContentResolver,Sqlite的关系
- 大三下计划
- Centos6 安装chrome
- Ubuntu11.10下激活ROOT帐号
- Windows Phone开发(3):棋子未动,先观全局
- [CodeProject每日一荐] TaskbarNotifier: 可换肤的 MSN Messenger-like 风格窗体( C# & VB.NET)
- The Unique MST
- SQLite3 使用教学
- 使用jQuery制作弹出窗口
- Android-SQLite3 超基础入门
- Cannot find or open the PDB file???
- LaszloSystems目前已经被Critical Path收购
- 女人非常Bra 要选就选right
- C++中的引用