很高兴找到一篇最近这个话题的新的文章:2006.3.23,一个长于编程,短于文档的程序员作品:)有时间准备把VB.NET翻译成C#版本.以便自己以后使用:)

An Office 2003-like popup notifier By Nick Wälti

[介绍/特色]
看图说话:
Office 2003新邮件通知的风格:
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)

渐隐渐出: 透明度
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)

可定制为MSN Messsenger风格:
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)

其他风格实例:
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)

该控件完全在代码中完成绘制,不依赖于System.DrawingSystem.Windows.Forms.你可以包含一个ContextMenuStrip,当点击第一个图中"向下"的箭头图标时显示出来.

[使用代码]
该控件有两个基本的类组成:

  • 一个 form (会实际显示出来的部分).
  • 一个包含所有可在form中包含的属性的类.

类包含两个timers, 一个用来控制渐隐渐出的动画效果,另一个可配置为定义弹出窗口显示多久.下面是一个演示:

[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)fPopup.Size = Size
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)fPopup.Opacity 
= 0
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)fPopup.Location 
= _
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)  
New Point(Screen.PrimaryScreen.WorkingArea.Right_
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)   
- fPopup.Size.Width - 1, _
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)   Screen.PrimaryScreen.WorkingArea.Bottom)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)fPopup.Show()

form在Paint事件中完成绘制. 笔者使用了一下函数来获取比指定颜色更浅/更深的颜色,但不确定是否有更好的方法.

End Function

为避免闪烁:
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)


[译者:内容很简洁,因为刚出来,才V1.0,肯定还会有所补充完善,下面摘取一些问题的评论和反馈]
[问题的评论和反馈]
[1]如何为控件实现一个隐藏窗体的方法
在PopupNotifier.vb 类中加入:
End Sub

在form中如此调用:

End Sub

[2]如何为控件实现一个定渐隐渐出速度的属性

[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)Private iAnimationDelay As Integer = 50
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)    
<Category("Behavior"), _
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)    DefaultValue(
50)> _

[3]如何实现类似MSN Messenger的同时处理多个提示消息的效果(向上层叠):
写一个PopupNotifierCollection封装多个PopupNotifier,加一个YOrigin属性来控制位置

[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)Imports System.ComponentModel
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
End Class

 

[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)Dim colPopupNotifiers As New PopupNotifierCollection
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
Dim pnNotifier1 As PopupNotifier = New PopupNotifier
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
Dim pnNotifier2 As PopupNotifier = New PopupNotifier
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)colPopupNotifiers.Add(pnNotifier1)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)colPopupNotifiers.Add(pnNotifier2)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)colPopupNotifiers.Popup()

Popup()会调用PopupNotifier的Popup(),PopupNotifier要做一些改变:
加入Private iOffset As Integer = 0
在Popup()中:

End Sub

在tmAnimation_Tick()中:

[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)...
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
If fPopup.Top + fPopup.Height < Screen.PrimaryScreen.WorkingArea.Bottom - iOffset
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)...
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)
If fPopup.Top > Screen.PrimaryScreen.WorkingArea.Bottom - iOffset
[CodeProject每日一荐] PopupNotifier: 一个Office 2003风格的通知控件(VB.NET)...

[4]如何隐藏任务栏上的小图标
在New中 加一句ShowInTaskbar = False.[译者:当然也可以定义为一种属性,方便重用]

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2021-07-28
  • 2021-12-04
  • 2021-11-28
  • 2021-06-09
  • 2021-11-24
  • 2021-08-21
猜你喜欢
  • 2022-01-11
  • 2021-05-17
  • 2022-02-24
  • 2021-11-21
  • 2021-09-15
  • 2021-11-01
  • 2021-10-08
相关资源
相似解决方案