Center Forms with Taskbar Visible

Just about every VB developer uses the Move (Screen.Width – Width) 2, (Screen.Height – Height) 2 method to center the forms on screen. However, when the user has the Windows 95 or NT 4.0 taskbar visible, your form centers on screen but doesn’t take into account the position of the taskbar itself. The CenterForm32 routine centers a form in available screen area, taking into account the taskbar. Add this code to the Declarations section of a module, and put the code CenterForm32 Me on the Form_Load event of the forms you want to center:

 Option ExplicitPrivate Const SPI_GETWORKAREA = 48Private Declare Function _	SystemParametersInfo& Lib "User32" _	Alias "SystemParametersInfoA" ( _	ByVal uAction As Long, _	ByVal uParam As Long, lpvParam As Any, _	ByVal fuWinIni As Long)Private Type RECT	Left As Long	Top As Long	Right As Long	Bottom As LongEnd TypePublic Function CenterForm32 (frm As Form)	Dim ScreenWidth&, ScreenHeight&, _		ScreenLeft&, ScreenTop&	Dim DesktopArea As RECT	Call SystemParametersInfo ( _		SPI_GETWORKAREA, 0, DesktopArea, 0)	ScreenHeight = (DesktopArea.Bottom - _		DesktopArea.Top) * Screen.TwipsPerPixelY	ScreenWidth = (DesktopArea.Right - _		DesktopArea.Left) * Screen.TwipsPerPixelX	ScreenLeft = DesktopArea.Left * Screen.TwipsPerPixelX	ScreenTop = DesktopArea.Top * Screen.TwipsPerPixelY	frm.Move (ScreenWidth - frm.Width)  _		 2 + ScreenLeft, (ScreenHeight - _		frm.Height)  2 + ScreenTopEnd Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS