Yet Another CenterForm Routine

In the April 1997 issue of VBPJ, you published a tip called “Consider the Taskbar When Centering Forms.” You can center forms more easily with the SystemParametersInfo API call:

 Private Declare Function _	SystemParametersInfo Lib "user32" Alias _	"SystemParametersInfoA" (ByVal uAction _	As Long, ByVal uParam As Long, R As Any, _	ByVal fuWinIni As Long) As LongPrivate Type RECT	Left As Long	Top As Long	Right As Long	Bottom As LongEnd TypePrivate Const SPI_GETWORKAREA = 48Public Sub CenterForm(frm As Form)	Dim R As RECT, lRes As Long, 	Dim lW As Long, lH As Long	lRes = SystemParametersInfo( _		SPI_GETWORKAREA, 0, R, 0)	If lRes Then		With R			.Left = Screen.TwipsPerPixelX * .Left			.Top = Screen.TwipsPerPixelY * .Top			.Right = Screen.TwipsPerPixelX * .Right			.Bottom = Screen.TwipsPerPixelY * .Bottom			lW = .Right - .Left			lH = .Bottom - .Top			frm.Move .Left + (lW - frm.Width)  2, _				.Top + (lH - frm.Height)  2		End With	End IfEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: