Make ChildForm Center MDI Form Screen

[Modul]

  1. Public Sub TB_Zone(frm As Form, Optional vntUseScaleValues As Variant)
  2. Dim bUseScaleValues As Boolean
  3. If Not IsMissing(vntUseScaleValues) Then
  4. bUseScaleValues = vntUseScaleValues
  5. End If
  6. With frm
  7. If bUseScaleValues Then
  8. TB_ZoneLeft = .ScaleLeft + .Left
  9. TB_ZoneTop = .ScaleTop + .Top
  10. TB_ZoneWidth = .ScaleWidth
  11. TB_ZoneHeight = .ScaleHeight
  12. Else
  13. TB_ZoneLeft = .Left
  14. TB_ZoneTop = .Top
  15. TB_ZoneWidth = .Width
  16. TB_ZoneHeight = .Height
  17. End If
  18. End With
  19. End Sub

  1. Public Sub TB_CenterForm(frm As Form, Optional vntOffsetLeft As Variant, Optional vntOffsetTop As Variant, Optional vntConsiderTaskbar As Variant)
  2. Dim lLeft As Long, lTop As Long
  3. Dim lOffsetLeft As Long
  4. Dim lOffsetTop As Long
  5. Dim bConsiderTaskbar As Boolean
  6. If Not IsMissing(vntOffsetLeft) Then
  7. lOffsetLeft = vntOffsetLeft
  8. End If
  9. If Not IsMissing(vntOffsetTop) Then
  10. lOffsetTop = vntOffsetTop
  11. End If
  12. If Not IsMissing(vntConsiderTaskbar) Then
  13. bConsiderTaskbar = vntConsiderTaskbar
  14. End If
  15. With frm
  16. If .WindowState = vbNormal Then
  17. If bConsiderTaskbar Then
  18. ElseIf TB_ZoneWidth + TB_ZoneHeight > 0 Then
  19. lLeft = (TB_ZoneLeft + (TB_ZoneWidth \ 2)) - (.Width \ 2) + lOffsetLeft
  20. lTop = (TB_ZoneTop + (TB_ZoneHeight \ 2)) - (.Height \ 2) + lOffsetTop
  21. If lLeft + .Width > Screen.Width Then
  22. lLeft = Screen.Width - .Width
  23. ElseIf lLeft <>
  24. lLeft = 0
  25. End If
  26. If lTop + .Height > Screen.Height Then
  27. lTop = Screen.Height - .Height
  28. ElseIf lTop <>
  29. lTop = 0
  30. End If
  31. Else
  32. lLeft = ((Screen.Width - .Width) \ 2) + lOffsetLeft
  33. lTop = (((Screen.Height - .Height) \ 2) + lOffsetTop)
  34. End If
  35. If .Left = lLeft And .Top = lTop Then
  36. Else
  37. .Move lLeft, lTop
  38. End If
  39. End If
  40. End With
  41. End Sub

[Form]

  1. Option Explicit
  2. Public TB_ZoneLeft As Long
  3. Public TB_ZoneTop As Long
  4. Public TB_ZoneWidth As Long
  5. Public TB_ZoneHeight As Long
  6. Private Sub CenterMDIForm()
  7. Dim lLeft As Long
  8. Dim lTop As Long
  9. Dim iTemp As Integer
  10. Dim sTemp As String
  11. Static bOnTop As Boolean
  12. TB_Zone Main_Form
  13. TB_CenterForm Me, lLeft, lTop
  14. End Sub
  15. Place/Call Sub CenterMDIForm at EVENT Form_Resize, Form_Load or EVENT Form_Activate
  16. Private Sub Form_Resize()
  17. CenterMDIForm
  18. End Sub
  19. Private Sub Form_Activate()
  20. CenterMDIForm
  21. End Sub
  22. Private Sub Form_Load()
  23. CenterMDIForm
  24. End Sub

Komentar

Postingan populer dari blog ini

Membuat Split File Zip Dengan 7-Zip

Load Dan Insert Image ke MySQL BLOB dengan VB6

Pembuatan Function PowerBuilder