none
How to hide form from Alt-Tab dialog

    Question

  • Hi,

    I'm creating a borderless form by setting this.FormBorderStyle = FormBorderStyle.None

    When I show the form, if users press Alt-Tab to switch among applications, they can still see it. How can I disable it ?

    Thanks a lot.
    Wednesday, August 24, 2005 2:03 AM

Answers

  • Paste this code into your borderless form:

        protected override CreateParams CreateParams {
          get {
            // Turn on WS_EX_TOOLWINDOW style bit
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x80;
            return cp;
          }
        }

    Monday, January 08, 2007 1:46 PM
    Moderator

All replies

  • Do I dare ask
    a) why
    and b) what FormBorderStyle has to do whether the application shows up in the Alt tab window?
    The property ShowInTaskbar  would have a greater possibility of controlling whether the application shows inthe Alt-Tab menu long before a borderstyle does.

    Wednesday, August 24, 2005 12:29 PM
  • I need the same thing. Does anyone have a suggestion for this. The reason I need this is it is a lightweight application that runs in the systray with no UI. It's function is just kick off other application on certain events firing. Alt-tab shows it as something you can switch to, but there isn't a visible form available, so it looks like the form wouldn't open up, when in reality, it is open, just invisible. ShowInTaskbar=false does not keep it from showing up in alt-tab dialog.
    Tuesday, January 24, 2006 8:37 PM
  • If your app runs in the systray, you shouldnt have any open forms. If there are no open forms, your app wont show up in Alt-tab. (You cant just hide a form, you have to close it).
    Wednesday, January 25, 2006 1:19 AM
  • I believe The reason that it shows in the taskbar is because of a trick that .NET uses to do the SysTray. I've noticed that if you set the show in taskbar to false and set the formborder to toolbar then it will not show up in the taskbar - I do not know whether this would override the hidden form that may be used for the systray icon.
    Thursday, December 21, 2006 3:02 PM
  • This is how you can remove, your application icon from the ALT + TAB menu.

    From what I can gather the ALT + TAB menu displays all windows owned by the desktop or whose owners are null. There are 2 ways that you can easily stop your main form from displaying under this menu.

    1) Change the border style of the main window to Fixed or Sizable tool windows.

    I dont like this approach but it also works ....

    2) In the main forms constructor: add this line of code

    this.Owner = new Form();

    Why would you want to do this? For stealth applications such as screen readers, markers and tray applications. In the case of a screen reader the main form is visible and the top most window at all times. (meaning you cannot escape it other than closing it) So although ms provides the property that says: ShowInTaskBar ... this unfortunatly only does half of the job. (if one thinks about it, it does not make sence to have these applications show under the  alt tab menu.)

    If anyone knows of another way (WIN32 call possibly) please let me know.

     

    Thanks

     

    Monday, January 08, 2007 11:45 AM
  • Paste this code into your borderless form:

        protected override CreateParams CreateParams {
          get {
            // Turn on WS_EX_TOOLWINDOW style bit
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x80;
            return cp;
          }
        }

    Monday, January 08, 2007 1:46 PM
    Moderator
  • Thanks, much better way of doing this, as it does not actually appear to change the borderstyle (GUI) of my borderless form, which would have been undesirable.
    Wednesday, January 17, 2007 1:57 PM
  • This trick works perfectly!!! Thanks a lot!
    Friday, June 08, 2007 5:23 PM
  • The overridden CreateParams trick still work! Quite useful - just wish it was higher in the search results.
    Tuesday, October 23, 2007 9:53 PM
  • Isn't this just another way of setting the form border style? It works, but does change the border for me.

    Monday, January 14, 2008 7:31 PM
  • Paste this code into your borderless form:

        protected override CreateParams CreateParams {
          get {
            // Turn on WS_EX_TOOLWINDOW style bit
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x80;
            return cp;
          }
        }


    this has worked for me thanks a lot :)

     

    Thursday, September 23, 2010 11:50 AM
  • Found the following useful (but not short) code for my WPF WindowStyle=None Application to solve this issue....

    http://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher/551847#551847

    Monday, September 09, 2013 6:48 PM