Results 1 to 4 of 4

Thread: [RESOLVED] How do you make the current form topmost?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    137

    Resolved [RESOLVED] How do you make the current form topmost?

    I am aware that you can set the form to topmost (Me.Topmost=True), but I want the CURRENT form to be on top. I have set the startup form as my Home form, which has buttons to 2 other forms, which have Me.Topmost=True set on each of them, but the Home form is always on top, even though I did not set it as topmost.
    Any idea why the new forms I open do not come to the front?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do you make the current form topmost?

    If you have set TopMost to True for one form and False for another then the first form will be displayed over the second. If that's not what you're seeing then either you haven't set those properties that way or your system is broken. There's no other magic property that we can tell you to set that will "fix" this issue because TopMost already does what TopMost does. Perhaps you could demonstrate to us how we can reproduce the issue because, without that, there's not really any way that we can tell you how to fix an issue that doesn't appear could possibly exist.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2015
    Location
    Hastings, UK
    Posts
    137

    Re: How do you make the current form topmost?

    I think I know where I have gone wrong! After writing this post and giving up for today I realised that I had been putting Me.Topmost=True on the Home form after the Show() command, whereas I should have put the command on each of the forms or perhaps used the name of the form instead of Me.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How do you make the current form topmost?

    If you want every instance of a particular form type to be on top by default then you should set the TopMost property to True for that form type in the designer, just like you set the Text or any other common property. If you want any particular instance to behave other than the default then you should be setting the TopMost property of that instance before showing it, e.g.
    vb.net Code:
    1. 'Display a specific instance of Form2 on top when Form2 is not on top by default.
    2. Dim f2 As New Form2
    3.  
    4. f2.TopMost = True
    5. f2.Show()
    6.  
    7.  
    8. 'Display the default instance of Form3 not on top when Form3 is on top by default.
    9. Form3.TopMost = False
    10. Form3.Show()
    The only time you should be setting TopMost of the current instance is if you have something within that form that would cause the property to change, e.g. the 'Always on top' item under the 'Options' menu in the Windows 'Task Manager' app.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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