把表单放在屏幕的正中央

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

在 开 发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 中 实 现。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航