该控件有两个基本的类组成:
一个 form (会实际显示出来的部分).
一个包含所有可在form中包含的属性的类.
类包含两个timers, 一个用来控制渐隐渐出的动画效果,另一个可配置为定义弹出窗口显示多久.下面是一个演示:
fPopup.Size = Size
fPopup.Opacity = 0
fPopup.Location = _
New Point(Screen.PrimaryScreen.WorkingArea.Right_
- fPopup.Size.Width - 1, _
Screen.PrimaryScreen.WorkingArea.Bottom)
fPopup.Show()
form在Paint事件中完成绘制. 笔者使用了一下函数来获取比指定颜色更浅/更深的颜色,但不确定是否有更好的方法.
Private Function GetDarkerColor()Function GetDarkerColor(ByVal Color As Color) As Color
Dim clNew As Color
clNew = Drawing.Color.FromArgb(255, DedValueMin0(CInt(Color.R), _
Parent.GradientPower), DedValueMin0(CInt(Color.G), _
Parent.GradientPower), DedValueMin0(CInt(Color.B), _
Parent.GradientPower))
Return clNew
End Function
为避免闪烁:
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
如何为控件实现一个隐藏窗体的方法
在PopupNotifier.
vb 类中加入:
Sub Hide()Sub Hide()
tmWait.Stop()
tmAnimation.Start()
End Sub
在form中如此调用:
Private Sub PopupNotifier1_Close()Sub PopupNotifier1_Close() Handles PopupNotifier1.Close
PopupNotifier1.Hide()
End Sub
如何为控件实现一个定渐隐渐出速度的属性
Private iAnimationDelay As Integer = 50
<Category("Behavior"), _
DefaultValue(50)> _
Property AnimationDelay()Property AnimationDelay() As Integer
Get
Return iAnimationDelay
End Get
Set(ByVal value As Integer)
iAnimationDelay = value
End Set
End Property
Sub Popup()Sub Popup()
tmAnimation.Interval = AnimationDelay
' . REST OF THE SUBROUTINE .
End Sub
如何实现类似MSN Messenger的同时处理多个提示消息的效果(向上层叠):
写一个PopupNotifierCollection封装多个PopupNotifier,加一个YOrigin属性来控制位置
Imports System.ComponentModel
Public Class PopupNotifierCollectionClassClass PopupNotifierCollectionClass PopupNotifierCollection
Inherits CollectionBase
Sub New()Sub New()Sub New()Sub New()
End Sub
Protected Overrides Sub OnSet()Sub OnSet()Sub OnSet()Sub OnSet(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
MyBase.OnSet(index, oldValue, newValue)
End Sub
Protected Overrides Sub OnInsert()Sub OnInsert()Sub OnInsert()Sub OnInsert(ByVal index As Integer, ByVal value