Advertisement
7_2009-2012 Custom Controls/ Forms/ Menus #217348

Center a form, relative to the available workspace

Centers a form, relative to the available workspace. This means that if your users have high, or wide taskbars, or other apps which restrict the workspace, your forms will still center properly.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Public Sub Center(ByRef frm As Form)
'Centers a form, relative to the available workspace
Dim rt As RECT, result As Long
Dim X As Single, Y As Single
Dim oldScaleMode As Integer
result = SystemParametersInfo(SPI_GETWORKAREA, 0&, rt, 0&)
X = rt.Right - rt.Left
Y = rt.Bottom - rt.Top
X = X * Screen.TwipsPerPixelX
Y = Y * Screen.TwipsPerPixelY
X = X \ 2 - (frm.Width \ 2)
Y = Y \ 2 - (frm.Height \ 2)
oldScaleMode = frm.ScaleMode
frm.ScaleMode = vbTwips
frm.Move X, Y
frm.ScaleMode = oldScaleMode
End Sub

Upload
Original Comments (3)
Recovered from Wayback Machine