vbnet窗口最前 vbnet关闭一个窗体
vb窗体总是在最前面的设置
使用WINDOWS API SetWindowPos函数来设置,在Form_Load中加入,如下示例即可:
成都网站设计、成都网站制作、外贸网站建设的开发,更需要了解用户,从用户角度来建设网站,获得较好的用户体验。成都创新互联多年互联网经验,见的多,沟通容易、能帮助客户提出的运营建议。作为成都一家网络公司,打造的就是网站建设产品直销的概念。选择成都创新互联,不只是建站,我们把建站作为产品,不断的更新、完善,让每位来访用户感受到浩方产品的价值服务。
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 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
retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX,
Me.CurrentY, 300, 300, SWP_SHOWWINDOW)
End Sub
这样窗体就能保持在所有窗体的前面了。
SetWindowPos函数的定义和参数:
使用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
其中各参数的意义如下:
参数 意义
hwnd Long 欲定位的窗口
hWndInsertAfter Long 窗口句柄。在窗口列表中,窗口hwnd会置于这个窗口句柄的后面
x,y Long 窗口新的x,y坐标
cx,cy Long 指定新的窗口宽度和高度
wFlags Long 包含了旗标的一个整数,是下列之一
返回值 Long 非零表示成功,零表示失败
下面是部分wFlags参数和它们的意义:
参数 意义和使用方法
SWP_DRAWFRAME 围绕窗口画一个框
SWP_HIDEWINDOW 隐藏窗口
SWP_NOACTIVATE 不激活窗口
SWP_NOMOVE 保持当前位置 (x和y设定将被忽略) H2
SWP_NOREDRAW 窗口不自动重画
SWP_NOSIZE 保持当前大小 (cx和cy会被忽略) H1
SWP_NOZORDER 保持窗口在列表的当前位置 (hWndInsertAfter将被忽略)
SWP_SHOWWINDOW 显示窗口 H40
SWP_FRAMECHANGED 强迫一条WM_NCCALCSIZE消息进入窗口,即使窗口的大小没有改变
怎样让.NET VB启动的程序都显示在最前面?
shell加个参数:
Shell("D:\Program Files\Microsoft Office\Office14\WINWORD.EXE", AppWinStyle.NormalFocus)
VB实现窗口最前但不要取得焦点
Private
Const
SWP_NOACTIVATE
=
H10
'不获得焦点
Private
Const
SWP_NOMOVE
=
2
Private
Const
SWP_NOSIZE
=
1
Private
Const
Flags
=
SWP_NOMOVE
Or
SWP_NOSIZE
Or
SWP_NOACTIVATE
Private
Const
HWND_TOPMOST
=
-1
Private
Const
HWND_NOTOPMOST
=
-2
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
'设置窗口总在最前的函数
Public
Function
SetTopMostWindow(tHWND
As
Long,
Topmost
As
Boolean)
As
Long
If
Topmost
=
True
Then
SetTopMostWindow
=
SetWindowPos(tHWND,
HWND_TOPMOST,
0,
0,
0,
0,
Flags)
Else
SetTopMostWindow
=
SetWindowPos(tHWND,
HWND_NOTOPMOST,
0,
0,
0,
0,
Flags)
SetTopMostWindow
=
False
End
If
End
Function
'使form2窗口总在最前,但不让form2获得焦点
Private
Sub
Command1_Click()
SetTopMostWindow
Form2.hwnd,
True
End
Sub
文章题目:vbnet窗口最前 vbnet关闭一个窗体
URL地址:http://ybzwz.com/article/docssge.html