本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 [署名 4.0 国际 (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/deed.zh) 本文作者: 苏洋 创建时间: 2009年05月03日 统计字数: 531字 阅读时间: 2分钟阅读 本文链接: https://soulteary.com/2009/05/03/vb-ontop-special.html ----- # [vb]前端显示的特殊写法 [vb]前端显示的特殊写法 ```vb 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 HWND_TOPMOST = -1 Private Const HWND_NOTOPMOST = -2 Private Const SWP_NOSIZE = &H1 Private Const SWP_NOMOVE = &H2 Public Property Let OnTop(frm As Form, Setting As Boolean) SetWindowPos frm.Hwnd, IIf(Setting, HWND_TOPMOST, HWND_NOTOPMOST), 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Property ``` 任意窗体事件中 : ```vb Private Sub Form_Load() OnTop = True End Sub ```