After you show the window, you can set the owner for the window.
Private Sub MyNotify_MouseClick(sender As Object, e As MouseEventArgs) Handles MyNotify.MouseClick
If e.Button = MouseButtons.Left Then
Me.ShowInTaskbar = False
MyMenu.Show(Cursor.Position)
SetWindowLongPtr(MyMenu.Handle, GWL_HWNDPARENT, Handle)
End If
End Sub
Private Const GWL_HWNDPARENT As Integer = -8
<DllImport("user32.dll", EntryPoint:="SetWindowLongPtr", SetLastError:=True)>
Private Shared Function SetWindowLongPtr64(hWnd As IntPtr, nIndex As Integer, dwNewLong As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="SetWindowLong", SetLastError:=True)>
Private Shared Function SetWindowLong32(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer
End Function
Private Shared Function SetWindowLongPtr(hWnd As IntPtr, nIndex As Integer, dwNewLong As IntPtr) As IntPtr
If IntPtr.Size = 8 Then
Return SetWindowLongPtr64(hWnd, nIndex, dwNewLong)
Else
Return New IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()))
End If
End Function