Impossible to set the window on top of the top of the top window?

二次信任 提交于 2020-01-17 08:05:37

问题


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

[EDIT]:

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

回答1:


Is it a VB.Net program your pointing too? Change the TopMost property of that form to True

Solution 1

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

Keep form open when clicking on another application

Dont forget that the form you will put the code is the form that you will show in your program

Update

Try This.

Solution 2

Dim form1 As Form = new Form
form.TopMost = True
form.Owner = Me
form.ShowDialog()
form.Dispose()

Solution 3

Dim frmMessage As New Form() frmMessage.Owner = form1 frmMessage.Show()



来源:https://stackoverflow.com/questions/41236914/impossible-to-set-the-window-on-top-of-the-top-of-the-top-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!