VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 游动的窗体
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8511, 日期:2001-06-14
示例二:游动的窗体

  朋友,您使用过Linux吗?如果您使用过的话,那么Linux中那只游动的可爱小企鹅,一定忘不了。其实,该功能实现很简单,下面,笔者将带您一起来实现它。

  实现步骤:

  1. 建立新项目文件DEMO2.PRJ;

  2. 建立模块文件DEMO2.BAS.并在模块中加入如下代码:

Public Declare Function GetCursorPos Lib "user32" (lpPoint As
POINTAPI) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Oldx As Long
Public Oldy As Long
Public Newx As Long
Public Newy As Long
Public Pnt As POINTAPI
   

  3.在窗体上加入一个时间控件Timer1_Timer处理程序中加入如下代码:

Private Sub Timer1_Timer()
Me.SetFocus
GetCursorPos Pnt
Oldx = Form1.Left
Oldy = Form1.Top
Newx = Pnt.X * 13.5
Newy = Pnt.Y * 13.5
incx = (Newx - Oldx) / 80 * 13.5
incy = (Newy - Oldy) / 80 * 13.5
Form1.Move Oldx + incx, Oldy + incy
End Sub


  4.在Image1_DblClick处理程序中加入如下代码:

Private Sub Image1_DblClick()
Unload Me
End Sub