目的
フォームを常に手前に表示します。
ポイント
APIのSetWindowPosを使用します。
サンプルコード
Option Explicit
Private Declare Function SetWindowPos _
Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, _
ByVal Cy As Long, ByVal wFlags As Long) As Long
Private Const conHwndTopmost = -1
Private Const conHwndNoTopmost = -2
Private Sub optSwitch_Click(Index As Integer)
' 常に手前に表示するサンプル
Select Case Index
Case 0 ' 通常
SetWindowPos Me.hwnd, conHwndNoTopmost, _
Me.Left / Screen.TwipsPerPixelX, _
Me.Top / Screen.TwipsPerPixelY, _
Me.Width / Screen.TwipsPerPixelX, _
Me.Height / Screen.TwipsPerPixelY, 0
Case 1 ' 常に手前に表示
SetWindowPos Me.hwnd, conHwndTopmost, _
Me.Left / Screen.TwipsPerPixelX, _
Me.Top / Screen.TwipsPerPixelY, _
Me.Width / Screen.TwipsPerPixelX, _
Me.Height / Screen.TwipsPerPixelY, 0
End Select
End Sub