Place the form on the center of the screen

xiaoxiao2021-03-06  38

When developing the VB program, it is generally desirable to put the form on the screen available area. The following code segment implements the positive of the screen when the screen is launched, whether the screen has a task bar, the form is in the screen. central.

Add a module in the project, together with the following code in the module: Option Explicit Private Const SPI_GETWORKAREA = 48 Private 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 Long End Type Public 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 =

转载请注明原文地址:https://www.9cbs.com/read-64833.html

New Post(0)