我有自助服务终端应用程序,我已经运行了自助服务终端应用程序但是在该窗口的顶部我需要放置一个永久可用的窗口,无论谁在顶部,该窗口必须位于顶部窗口的顶部始终位于顶部。
我尝试了几种方式,但仍然无法在窗口的顶部停留在窗口顶部
为什么我的应用程序仍然无法保持在顶部?
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是我的,所有其他人都更加优先考虑然后我保持领先。我怎么能在所有这些之上?
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
答案 0 :(得分:1)
你指点的是VB.Net程序吗?将该表单的TopMost
属性更改为True
解决方案1
或者在您的表单中将Me.TopMost = True
添加到您的Form_LostFocus
这里是我也回答它的链接,就像我给你的那样,你有同样的问题
Keep form open when clicking on another application
不要忘记您将代码的表单是您将在程序中显示的表单
更新
试试这个。
解决方案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()