Berikut kodenya yang dibuat dengan Microsoft Visual Basic 6.0:
'Kode pada form1
Option Explicit
Private Sub Timer1_Timer()
PosisikanForm Form1
End Sub
'Kode pada module
Option Explicit
Private Declare Function GetCursorPosXY Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Public Sub GetCursorPos(xX As Long, xy As Long)
Dim pt As POINTAPI
Call GetCursorPosXY(pt)
xX = pt.x
xy = pt.y
End Sub
Public Sub PosisikanForm(frm As Form)
Dim x As Long
Dim y As Long
GetCursorPos x, y
'Kode di bawah merupakan inti dari project ini dengan fungsi yang telah diperbaiki
If ((y) + frm.Height / 15) > (Screen.Height / Screen.TwipsPerPixelY) Then
frm.Top = (y * 15) - (frm.Height)
Else
frm.Top = (y * 15) + 200
End If
If ((x) + frm.Width / 15) > (Screen.Width / Screen.TwipsPerPixelX) Then
frm.Left = (x * 15) - frm.Width
Else
frm.Left = (x * 15) + 200
End If
End Sub