Make ChildForm Center MDI Form Screen
[Modul]
[Form]
- Public Sub TB_Zone(frm As Form, Optional vntUseScaleValues As Variant)
- Dim bUseScaleValues As Boolean
- If Not IsMissing(vntUseScaleValues) Then
- bUseScaleValues = vntUseScaleValues
- End If
- With frm
- If bUseScaleValues Then
- TB_ZoneLeft = .ScaleLeft + .Left
- TB_ZoneTop = .ScaleTop + .Top
- TB_ZoneWidth = .ScaleWidth
- TB_ZoneHeight = .ScaleHeight
- Else
- TB_ZoneLeft = .Left
- TB_ZoneTop = .Top
- TB_ZoneWidth = .Width
- TB_ZoneHeight = .Height
- End If
- End With
- End Sub
- Public Sub TB_CenterForm(frm As Form, Optional vntOffsetLeft As Variant, Optional vntOffsetTop As Variant, Optional vntConsiderTaskbar As Variant)
- Dim lLeft As Long, lTop As Long
- Dim lOffsetLeft As Long
- Dim lOffsetTop As Long
- Dim bConsiderTaskbar As Boolean
- If Not IsMissing(vntOffsetLeft) Then
- lOffsetLeft = vntOffsetLeft
- End If
- If Not IsMissing(vntOffsetTop) Then
- lOffsetTop = vntOffsetTop
- End If
- If Not IsMissing(vntConsiderTaskbar) Then
- bConsiderTaskbar = vntConsiderTaskbar
- End If
- With frm
- If .WindowState = vbNormal Then
- If bConsiderTaskbar Then
- ElseIf TB_ZoneWidth + TB_ZoneHeight > 0 Then
- lLeft = (TB_ZoneLeft + (TB_ZoneWidth \ 2)) - (.Width \ 2) + lOffsetLeft
- lTop = (TB_ZoneTop + (TB_ZoneHeight \ 2)) - (.Height \ 2) + lOffsetTop
- If lLeft + .Width > Screen.Width Then
- lLeft = Screen.Width - .Width
- ElseIf lLeft <>
- lLeft = 0
- End If
- If lTop + .Height > Screen.Height Then
- lTop = Screen.Height - .Height
- ElseIf lTop <>
- lTop = 0
- End If
- Else
- lLeft = ((Screen.Width - .Width) \ 2) + lOffsetLeft
- lTop = (((Screen.Height - .Height) \ 2) + lOffsetTop)
- End If
- If .Left = lLeft And .Top = lTop Then
- Else
- .Move lLeft, lTop
- End If
- End If
- End With
- End Sub
[Form]
- Option Explicit
- Public TB_ZoneLeft As Long
- Public TB_ZoneTop As Long
- Public TB_ZoneWidth As Long
- Public TB_ZoneHeight As Long
- Private Sub CenterMDIForm()
- Dim lLeft As Long
- Dim lTop As Long
- Dim iTemp As Integer
- Dim sTemp As String
- Static bOnTop As Boolean
- TB_Zone Main_Form
- TB_CenterForm Me, lLeft, lTop
- End Sub
- Place/Call Sub CenterMDIForm at EVENT Form_Resize, Form_Load or EVENT Form_Activate
- Private Sub Form_Resize()
- CenterMDIForm
- End Sub
- Private Sub Form_Activate()
- CenterMDIForm
- End Sub
- Private Sub Form_Load()
- CenterMDIForm
- End Sub
Komentar
Posting Komentar