How to keep window always on top

前端 未结 3 1545
自闭症患者
自闭症患者 2021-01-16 06:35

How I can keep my window staying always on top even if there is a window of another application with Topmost = true option activated and trying to stay in front

相关标签:
3条回答
  • 2021-01-16 06:55

    You can do a platform invoke on BringWindowToTop to achieve this:

    [DllImport("user32.dll", SetLastError=true)]
    static extern bool BringWindowToTop(IntPtr hWnd);
    
    [DllImport("user32.dll", SetLastError=true)]
    static extern bool BringWindowToTop(HandleRef hWnd);
    

    And call to it when the FocusLost event fires.

    0 讨论(0)
  • 2021-01-16 06:57

    Easiest way(assuming you allready have topmost promery set) would be calling

    myform.BringToFront();
    

    on FIXED but relativly small time intervals(see Timer class), through all the time form must stay on top.

    If calling this was conected to event that inform you of losing privileg of beeing on top, that could possibly cause resource-fihgts between multiple applications. Price of beeing safe is that some other program might be cheating by lisstening to informations when he is overthroned by your program, but the only solution for you wolud than be to kill that other program if you want to stay on top all the time :D

    0 讨论(0)
  • 2021-01-16 07:00

    It should be possible by setting the Focus on window, from OnFocusLost event handler.

    0 讨论(0)
提交回复
热议问题