一、主要用到的函数是API函数AnimateWindow。下面来简单的介绍一下这个函数的使用。
1 函数声明
'声明API函数AnimateWindow。该函数可以动态的操作窗体 Declare Function AnimateWindow Lib "user32" Alias "AnimateWindow" (ByVal hwnd As IntPtr, ByVal dwTime As Int32, ByVal dwFlags As Int32) As Boolean2,参数设置
Module Module1 '从左到右显示 Public Const AW_HOR_POSITIVE As Int32 = &H1 '从右到左显示 Public Const AW_HOR_NEGATIVE As Int32 = &H2 '从上到下显示 Public Const AW_VER_POSITIVE As Int32 = &H4 '从下到上显示 Public Const AW_VER_NEGATIVE As Int32 = &H8 '若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口 Public Const AW_CENTER As Int32 = &H10 Public Const AW_HIDE As Int32 = &H10000 '隐藏窗口,缺省则显示窗口 '激活窗口。在使用了AW_HIDE标志后不能使用这个标志 Public Const AW_ACTIVATE As Int32 = &H20000 '使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略 Public Const AW_SLIDE As Int32 = &H40000 '透明度从高到低 Public Const AW_BLEND As Int32 = &H80000 '判断窗体是否隐藏 Public Ishide As Boolean End Module
'*************************************************************************** '作者:章鱼哥,QQ:3107073263 群:309816713 '如有想要源码或好的建议请联系我,大家一起进步 '群里正在建设,欢迎参加讨论 '**************************************************** Public Class Form_Main ' 显示在屏幕的右下角 Dim Rect As Rectangle = Screen.PrimaryScreen.WorkingArea '获取电脑桌面屏幕 Dim X As Integer '提示窗口的Left值 Dim Y As Integer '提示窗口的Top值 '声明API函数AnimateWindow。该函数可以动态的操作窗体 Declare Function AnimateWindow Lib "user32" Alias "AnimateWindow" (ByVal hwnd As IntPtr, ByVal dwTime As Int32, ByVal dwFlags As Int32) As Boolean ' 窗体初始化 Private Sub Form_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load X = Rect.Width - Me.Width Y = Rect.Height - Me.Height Me.SetBounds(X, Y, Me.Width, Me.Height) '定义窗体位置 Timer1.Enabled = True '开启Timer控件 '将窗体设置成无边框格式。这样是有道理的,不信你吧这段代码注释掉试试 Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None End Sub '显示 Private Sub ShowForm() '三种方式都可以用,想用哪种就注释另外两种 'AnimateWindow(Me.Handle, 2000, AW_VER_NEGATIVE Or AW_HOR_NEGATIVE) '右上飞出 AnimateWindow(Me.Handle, 2000, AW_CENTER) '中间扩散 'AnimateWindow(Me.Handle, 2000, AW_BLEND)’由浅变深 Ishide = False End Sub '隐藏 Private Sub HideForm() 'AnimateWindow(Me.Handle, 2000, AW_HIDE Or AW_VER_POSITIVE)'由上向下飞出 'AnimateWindow(Me.Handle, 2000, AW_HIDE Or AW_VER_POSITIVE Or AW_HOR_POSITIVE) '由左上角向右下飞出 AnimateWindow(Me.Handle, 2000, AW_HIDE Or AW_BLEND) '窗体慢慢透明淡出 Ishide = True End Sub '定时器,隔3秒交替显示或隐藏 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Ishide Then ShowForm() Else HideForm() End If End Sub End Class好了,试试效果吧!祝好 章鱼哥
VB.NET 章鱼哥出品--利用API函数AnimateWindow创建Popup提示窗口
原文地址:http://blog.csdn.net/zhangyubishoulin/article/details/41012983