把表单放在屏幕的正中央

来源:互联网 发布:spring mvc php 编辑:程序博客网 时间:2024/04/29 20:47

 

                                在 开 发VB 程 序 时, 一 般 希 望 将 表 单 放 在 屏 幕 可 利 用 区 域 的正 中 央, 下 面 的 代 码 段 实 现 了 在 每 次 启 动 应 用 程 序 时, 无 论 屏 幕 是 否 有 任 务 条, 表 单 都 会 处 于 屏 幕 可 利 用 区 域 的 正 中 央。 在 工 程 中 增 添 一 模 块, 在 模 块 中 加 上 如 下 的 代 码: 

                                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 = DesktopArea.Top *
                              Screen.TwipsPerPixelY
                                frm.Move (ScreenWidth - frm.Width)/ 2 +
                              ScreenLeft, (ScreenHeight - frm.Height) / 2 +
                              ScreenTop
                                End Function
                                
     要 调 用CenterForm32 函 数, 可 在 表 单 的Load 事 件 中 增 添 代 码CenterForm32 Me 即 可。 以 上 代 码 在VB6 中 实 现。 

 

   

原创粉丝点击