无法将窗口设置在顶部窗口的顶部吗?
我有信息亭应用程序,我已经在运行信息亭应用程序,但是在该窗口的顶部,我需要放置一个永远可用的窗口,无论谁在顶部,该窗口都必须在窗口的顶部始终位于顶部窗口的顶部.
I have kiosk application, where i have already kiosk application running but on top of that window i need to put one of my window which is forever available no matter who ever is on top, that window has to be on top of the top of the very top window as always on top.
我尝试了几种方法,但仍然无法将其停留在整个窗口顶部
i tried several way but still it fails to stay on top of the window out all top of the window
为什么我的应用程序仍然无法停留在最顶端?
Why is my application still unable to stay to the very top of the top?
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
End Function
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
Public Function MakeTopMost()
SetWindowPos(Me.Handle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Function
Public Function MakeNormal()
SetWindowPos(Me.Handle(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.TransparencyKey = Color.LightBlue
Me.BackColor = Color.LightBlue
End Sub
Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
Me.Top = 5
Me.Left = 1185
Me.Visible = True
Me.BringToFront()
'Me.TopMost = True
Me.MakeTopMost()
'Me.BackColor = Color.Transparent
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Shell("cmd.exe /c cd C:\ & taskkill /f /im testingVB.net.exe", AppWinStyle.Hide)
End
End Sub
End Class
:
我也尝试了Me.TopMost = True和后续事件,但是我的RED十字架仍然不在其他所有顶级窗口的顶部.看到下面的RED是我的,而其他所有对象都比我拥有更高的优先级,所以我要保持领先.我怎么能在所有这些之上?
I tried Me.TopMost = True and following event too, but still my RED cross is not on top of all the other on top windows. see below the RED is mine and all others are taking more priority then me to stay on top. how can i be on top of all those?
Private Sub Form1_LostFocus(sender As Object, e As EventArgs) Handles Me.LostFocus
MsgBox("lost")
Me.Top = 5
Me.Left = 1185
Me.Visible = True
Me.BringToFront()
'Me.TopMost = True
Me.MakeTopMost()
'Me.BackColor = Color.Transparent
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Top = 5
Me.Left = 1185
Me.Visible = True
Me.BringToFront()
'Me.TopMost = True
Me.MakeTopMost()
'Me.BackColor = Color.Transparent
End Sub
您是否也指向VB.Net程序?将该窗体的TopMost
属性更改为True
Is it a VB.Net program your pointing too? Change the TopMost
property of that form to True
解决方案1
或者在您的表单中将此Me.TopMost = True
添加到您的Form_LostFocus
中,这是链接,我的回答也与我给您的相同,您有同样的问题
Or in your form add this Me.TopMost = True
in your Form_LostFocus
here is the link I also answer it the same as I given to you, you have the same problem
不要忘记您将要放置代码的表单就是您将在程序中显示的表单
Dont forget that the form you will put the code is the form that you will show in your program
更新
尝试一下.
解决方案2
Dim form1 As Form = new Form
form.TopMost = True
form.Owner = Me
form.ShowDialog()
form.Dispose()
解决方案3
Dim frmMessage As New Form()
frmMessage.Owner = form1
frmMessage.Show()
Dim frmMessage As New Form()
frmMessage.Owner = form1
frmMessage.Show()