Results 1 to 9 of 9

Thread: How Do I Keep A Window As The Top-Most Window Only In My Application?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    How Do I Keep A Window As The Top-Most Window Only In My Application?

    There doesn't seem to be anything about it :S

  2. #2
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    Quote Originally Posted by Louix View Post
    There doesn't seem to be anything about it :S
    I offer this feature in my latest app. Here's my code, verbatim:

    vb.net Code:
    1. Private Sub AlwaysOnTopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlwaysOnTopToolStripMenuItem.Click
    2.  
    3.     'Save Setting
    4.     If SaveSettingsToolStripMenuItem.Checked Then My.Settings.setAlwaysOnTop_Checked = AlwaysOnTopToolStripMenuItem.Checked
    5.  
    6.     Me.TopMost = Not Me.TopMost
    7. End Sub

    AlwaysOnTopToolStripMenuItem has the property CheckOnClick = True

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    Thanks, but this isn't what I'm looking for. I have a Toolbox form, and it's meant to stay on top of all other windows only in my application (not a dialog). When the application loses focus, this window is no longer topmost.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    if you use .showdialog instead of .show, your form will stay topmost within your application. but, it'll be displayed as a modal dialog

  5. #5
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    Quote Originally Posted by Louix View Post
    Thanks, but this isn't what I'm looking for. I have a Toolbox form, and it's meant to stay on top of all other windows only in my application (not a dialog). When the application loses focus, this window is no longer topmost.
    .ShowDialog() instead of .Show()

    Edit: slower than paul.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    Quote Originally Posted by Louix View Post
    Thanks, but this isn't what I'm looking for. I have a Toolbox form, and it's meant to stay on top of all other windows only in my application (not a dialog). When the application loses focus, this window is no longer topmost.
    Thanks, but I said I didn't want a dialog, just a tool window that sticks on top of all the other windows in my application while my application has focus, then when another application is selected, this topmost property turns off.

  7. #7
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    I'm not sure if there's a specific way of detecting whether the application has "lost focus" in .Net, in the good old days of VB6 and beyond you would use sub-classing. There are plenty of examples that can probably be leveraged into .Net if needed.

    If you can detect when your application loses focus you could then set the TopMost property of your form to False as necessary.

    An example of how to trap that in VB6 is here.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    Thank you , but the msghook library appears to be VB6 only

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: How Do I Keep A Window As The Top-Most Window Only In My Application?

    you can use a wndProc in vb.net to trap messages

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