Results 1 to 8 of 8

Thread: forcing form infront[Resolved]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    forcing form infront[Resolved]

    Hi

    Was wondering if it is possible in C# to make a form stay infront of another form until they press a button or close the dialog properly?

    For example, in MessageBox's - if you try to click on the form behind the MessageBox, it will not allow you to until you click the appropriate button on the MessageBox.

    Many thanks!
    Last edited by Techno; Feb 1st, 2006 at 12:12 PM.

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: forcing form infront

    set its TopMost property to True, and use it as a dialog .ShowDialog

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: forcing form infront

    Just use ShowDialog(). If you use TopMost as well, they won't be able to see some other applications because your form will be in their way (since it puts it at the top of all windows) which is very annoying.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: forcing form infront

    ok ill give the top most a shot and see what happens.

    anything else?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: forcing form infront

    Ok, that top most is cool but I wanna go a step further.

    When the user clicks on the previous/behind form from this top most form, i dont want them to use/click the behind form at all - like a message box.

    I also do not want to hide/show the main form - pretty much I would like it the way it acts on a MessageBox

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: forcing form infront

    ShowDialog(); seems to do the trick

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: forcing form infront

    I would still recommend not using TopMost. It's not very user friendly and I tend to uninstall anything that does that because I like to work in multiple applications.

    Also, please mark your thread as resolved.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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

    Re: forcing form infront

    ShowDialog and TopMost are intended for two quite different purposes. ShowDialog creates a modal dialogue, which is what it sounds like is needed here, where the user cannot access the calling form until the dialogue is dismissed. Using the TopMost property is good when you need the user to be able to see your application while working in another, like Task Manager. Like Task Manager again, it is always polite to provide an option to turn off that behaviour that would set your Form's TopMost property back to False.
    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

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