Declare Function ReleaseCapture Lib "user32" () As Long Declare
Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
再在控制的Mousedown事件中插入:
Sub Command1_MouseDown (Button As
Integer, Shift As Integer, X As Single, Y As Single) Dim
Ret& ReleaseCapture Ret& = SendMessage(Me.hWnd, &H112,
&HF012, 0) End Sub
二、 把表单放在屏幕的正中央
----
在开发VB程序时,一般希望将表单放在屏幕可利用区域的正中央,实现上可以利用Move(Screen.Width -
Width)\2,(Screen.Height - Height)\2的方法来实现。但是当用户使用Windows 95或 NT 操作系统时,在
屏幕底端会有一任务条,上述的实现方法并未考虑该任务条所占的空间,表单实际并未处于屏幕可利用区域的正中央。下面的代码段实现了在每次启动应用程序时,无论屏幕是否有任务条,表单都会屏幕可利用区域的正中央。在工程中增添一模块,在模块中加上如下的代码:
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 d
Function