1、可以使用ShowDialog()。ShowDialog()将其置于程序最顶层,而且不能使用当前程序的其它窗体。
2、可以设置Form.TopMost 属性为true,关于此属性的介绍:
Form.TopMost 属性获取或设置一个值,指示该窗体是否应显示为最顶层窗体。
命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)
参考代码与注释:
private void CreateMyTopMostForm(){
// Create lower form to display.
Form bottomForm = new Form()
// Display the lower form Maximized to demonstrate effect of TopMost property.
bottomForm.WindowState = FormWindowState.Maximized
// Display the bottom form.
bottomForm.Show()
// Create the top most form.
Form topMostForm = new Form()
// Set the size of the form larger than the default size.
topMostForm.Size = new Size(300,300)
// Set the position of the top most form to center of screen.
topMostForm.StartPosition = FormStartPosition.CenterScreen
// Display the form as top most form.
topMostForm.TopMost = true
topMostForm.Show()
}
两者二选一即可。
PrivateDeclare
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
SWP_NOSIZE&
=
&H1
'
保持窗口大小
Private
Const
SWP_NOMOVE&
=
&H2
'
保持窗口位置
Private
Sub
Form_Load()
SetWindowPos
Me.hwnd,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE
Or
SWP_NOSIZE
'
将窗口设为总在最前
End
Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)