dcsimg
Results 1 to 3 of 3

Thread: form on top of all

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,440

    form on top of all

    Hi.
    I'm trying to set a form over another applications but it will just show on the background.
    It may be that this app is trying to stay on top by itself but I cannot confirm this yet.
    Anyhow I'm trying (in a timer) some combinations of:
    Me.WindowState = FormWindowState.Maximized
    Me.Visible = True
    TopMost = True
    TopMost = False ' I saw this on a thread that said that doing that will "shake" the form and get it on top but I'm doing variations anyhow.
    (haven't tried me.activated yet)
    But it will always show the form behind. Doing so on the desktop with many apps open(except the specific not working app) it will show it on top .
    Any thoughts?
    Thanks.
    Slow as hell.

  2. #2
    Hyperactive Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    485

    Re: form on top of all

    This should do the trick:
    Code:
    Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
    Private Const SWP_NOSIZE As UInt32 = &H1
    Private Const SWP_NOMOVE As UInt32 = &H2
    Private Const TOPMOST_FLAGS As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
    
    <DllImport("user32.dll")>
    Public 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 UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function
    Code:
    SetWindowPos(Me.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS)

    Edit: On second glance, maybe the flags should be changed
    Last edited by Arve K.; Feb 13th, 2019 at 01:34 PM.
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,440

    Re: form on top of all

    I am first trying to use the standard forms way and then get to Pinvoke.
    If I get to Pinvoke then I would probably hide the other application.
    So I think I found something. In a part of the code I was setting the form as FormWindowState.Minimized when I was also using visible = false. I guess after that, even if I maximized the form again gave it "secondary priority" regarding the showing on top. I would test this tomorrow again and if I don't make it I would consider other options.
    Thanks.
    Slow as hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width