Di bawah ini merupkan procedure untuk menyimpan/memindahkan form tepat di tengah layar.
Option Explicit
Private Sub CenterForm(frmIn As Object)
Dim iTop As Integer, ileft As Integer
If frmIn.WindowState <> 0 Then
'prevent if form maximized or minimized
'the form must in normal condition
Exit Sub
End If
ileft = (Screen.Width - frmIn.Width) \ 2
iTop = (Screen.Height - frmIn.Height) \ 2
frmIn.Move ileft, iTop
End Sub
Cara penggunaan kode di atas:
Private Sub Form_Load()
Form_Resize
End Sub
Private Sub Form_Resize()
CenterForm Me
End Sub