Results 1 to 8 of 8

Thread: 'TopMost' window will NOT 'BringToFront' ?

  1. #1

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60

    Question 'TopMost' window will NOT 'BringToFront' ?

    I have a small application that runs for the most part as a task tray icon – although can be expanded into a window.
    This application has another form which is used as a popup msg window which connects to a database popups up alert msgs as and when any are set.

    This works fine, and has gone through test and is now out live.

    I am now having people report that the popup window does not actually popup – on investigation I’ve discovered that it is sat behind all the windows on the screen, including in some cases the main application window of the same program.

    This is despite having called the.BringToFront command where the popup window is shown. It is even set to TopMost = True – so why on earth is it not on top of its own application windows and behind all windows?!?!?

    I can’t for the life of me replicate this problem on my dev machine or within test – so what circumstance could possible prevent a window from coming to the top?!?!
    As it stands, this problem destroys the whole purpose of this program!

    This is using VS.NET 2002.

    Has anyone else had this kind of problem or can suggest ways around it – e.g. how to I force a window to come to the front of the screen?

    Many thanks for any help.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    on the form load event of the pop up windows try:

    Me.Focus

    thats should do it......bringtofront is a method for objects with in the form i thought....like if you have a text box over a label you could do label.bringtofront to make the label appear over the textbox (textbox wouldnt be visible where the label covered)

    it should look something like this:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3. me.focus
    4.  
    5. some other code here blah blah blah

    change the Form1 to whatever you named the form.....or just double click on the form in the IDE to get to the event in code.

  3. #3

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Trouble is I don't want the form to take focus... idea is, users are merrily working away... an alert will popup on screen so that they can see it but it wont take focus and thus interrupt them typing or whatever.
    this aspect is very important

    Also, I keep the form loaded after it's first displayed as a history of alerts is kept within that form.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    so what you are saying is you want it to pop up but not have focus but still be on top of everything??? kind of like some apps that allow you to Keep Window on top....like realplayer lets you...it stays out front no matter what but when you click off of it to another app it keeps running on top but you can type in the other app and do whatever?

  5. #5

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    Yep, that's exactly what I want!

    And it works on my dev PC, and the test team didn't flag it up, and I've as yet been unable to replicate the problem even on users PC's who have reported the problem.

    BUT... I am still getting reports from people who are saying the have to minimize most if not all windows before they can get to the msg box.... which is meant to be TopMost=True!

    I'm a bit stumped at the moment as to why/how this could be happening!

  6. #6

    Thread Starter
    Member McBain2's Avatar
    Join Date
    Sep 2003
    Location
    UK, Glos.
    Posts
    60
    See as per screenshot, it works for me!

    (The form is set TopMost=True by design and worked before for me without the additional lines I have been experimenting with around the hilighted .Show command)

    What could stop this from working? A bug in .NET perhaps?
    Attached Images Attached Images  

  7. #7
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    could you send me a copy of the project or....an exe file so i could test it?

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    TopMost is limited to the application windows and even at that may be limited to non-modal windows. I'm not sure why it isn't popping up in front of it's own though. I would recommend using the SetWindowPos API to set the form as TopMost for All windows regardless of application. You'll need to test for the focus issue but I believe you can show the form without focus even using the API.
    VB Code:
    1. Imports Microsoft.Win32
    2.  
    3. Public Class APIFunctions
    4.     'This class contains some of the API functions that i haven't found a way around in .NET yet.
    5.     'Primarily related to playinf sounds.
    6.  
    7.     Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Int32, ByVal hWndInsertAfter As Int32, ByVal x As Int32, ByVal y As Int32, ByVal cx As Int32, ByVal cy As Int32, ByVal wFlags As Int32) As Int32
    8.     Private Const HWND_TOPMOST As Integer = -1
    9.     Private Const HWND_NOTOPMOST As Integer = -2
    10.     Private Const SWP_NOMOVE As Integer = &H2
    11.     Private Const SWP_NOSIZE As Integer = &H1
    12.     Private Const TOPMOST_FLAGS As Integer = SWP_NOMOVE Or SWP_NOSIZE
    13.  
    14.     Public Shared Sub SetTopMost(ByVal frm As Form, ByVal topmost As Boolean)
    15.         If topmost Then
    16.             SetWindowPos(frm.Handle.ToInt32, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS)
    17.         Else
    18.             SetWindowPos(frm.Handle.ToInt32, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS)
    19.         End If
    20.     End Sub
    21.  
    22. End Class
    23.  
    24. 'syntax
    25. APIFunctions.SetTopMost(Me, True)

Posting Permissions

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



Click Here to Expand Forum to Full Width