VB里,怎么使form2显示,置顶。 启动窗体:form1。 用一个按钮。 求代码
2个回答
展开全部
Private Sub Command1_Click()
Form2.Show
End Sub
以上Form2代码不变
下面是Form2代码
Option Explicit
'窗口总在最前面所需要的API函数
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
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
Dim retValue As Long
Rem 调用API函数,将窗体设置为处于所有窗口的顶层
Rem 200,200是窗体左上角的位置,600,300是窗体的宽度和高度
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, 200, 200, 600, 300, SWP_SHOWWINDOW)
End Sub
Form2.Show
End Sub
以上Form2代码不变
下面是Form2代码
Option Explicit
'窗口总在最前面所需要的API函数
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
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
Dim retValue As Long
Rem 调用API函数,将窗体设置为处于所有窗口的顶层
Rem 200,200是窗体左上角的位置,600,300是窗体的宽度和高度
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, 200, 200, 600, 300, SWP_SHOWWINDOW)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询