Option Explicit Private Declare Function SHAppBarMessage Lib "shell32.dll" _ (ByVal dwMessage As Long, pData As APPBARDATA) As LongPrivate Const ABM_GETTASKBARPOS = &H5 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type APPBARDATA cbSize As Long hWnd As Long uCallbackMessage As Long uEdge As Long rc As RECT lParam As Long End TypePrivate Sub Form_Load() Dim MyData As APPBARDATA MyData.cbSize = Len(MyData) Call SHAppBarMessage(ABM_GETTASKBARPOS, MyData) '任務欄有三個邊都在屏幕外2個像素 With MyData.rc If .Top > 0 Then '任務欄在最下面 Me.Move (Screen.Width - Width) \ 2, (.Top * Screen.TwipsPerPixelY - Height) \ 2 ElseIf .Bottom < Screen.Height \ Screen.TwipsPerPixelY Then '任務欄在頂上 Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height + .Bottom * Screen.TwipsPerPixelY) \ 2 ElseIf .Left > 0 Then '在最右邊 Me.Move (.Left * Screen.TwipsPerPixelX - Width) \ 2, (Screen.Height - Height) \ 2 Else Me.Move (Screen.Width - Width + .Right * Screen.TwipsPerPixelX) \ 2, (Screen.Height - Height) \ 2 End If End With End Sub
Private Declare Function SHAppBarMessage Lib "shell32.dll" _
(ByVal dwMessage As Long, pData As APPBARDATA) As LongPrivate Const ABM_GETTASKBARPOS = &H5
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type APPBARDATA
cbSize As Long
hWnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long
End TypePrivate Sub Form_Load()
Dim MyData As APPBARDATA MyData.cbSize = Len(MyData)
Call SHAppBarMessage(ABM_GETTASKBARPOS, MyData)
'任務欄有三個邊都在屏幕外2個像素
With MyData.rc
If .Top > 0 Then '任務欄在最下面
Me.Move (Screen.Width - Width) \ 2, (.Top * Screen.TwipsPerPixelY - Height) \ 2
ElseIf .Bottom < Screen.Height \ Screen.TwipsPerPixelY Then '任務欄在頂上
Me.Move (Screen.Width - Width) \ 2, (Screen.Height - Height + .Bottom * Screen.TwipsPerPixelY) \ 2
ElseIf .Left > 0 Then '在最右邊
Me.Move (.Left * Screen.TwipsPerPixelX - Width) \ 2, (Screen.Height - Height) \ 2
Else
Me.Move (Screen.Width - Width + .Right * Screen.TwipsPerPixelX) \ 2, (Screen.Height - Height) \ 2
End If
End With
End Sub