Sunday, April 4, 2010

VB6 Code - Menyimpan Form Di Tengah Layar (screen)

Di bawah ini merupkan procedure VB6 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 VB6 di atas:
Private Sub Form_Load()
Form_Resize
End Sub

Private Sub Form_Resize()
CenterForm Me
End Sub