Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,
How can I hide my form from [alt+tab] menu in windows7?

I tried this :
this.showintaskbar=false;
this.windowstate=formwindowstate.minimum;
this.text="";

the purpose from last line is to hide my form from task manager.
with this code my form was hidden from taskbar , notification icons area , but it still show when i press [Alt+Tab].

Thanks in advance.
Posted
Updated 29-Apr-11 14:23pm
v2
Comments
Tarakeshwar Reddy 29-Apr-11 16:32pm    
And why would you want to do that? Can you not create a windows service?
Sergey Alexandrovich Kryukov 29-Apr-11 20:58pm    
You're absolutely right about Windows Service, I credited this idea in my answer and added a reference (I would vote for this idea).

My solution is ***way more simple***, however it' is unusual and kind of funny, but I know it works.
Please see :-)
--SA
mohammadrefaie 29-Apr-11 16:36pm    
i want to make my app work in back ground and only appears in notification icons area such as many apps.
Can you tell me more about windows service??
Sergey Alexandrovich Kryukov 29-Apr-11 20:59pm    
This is pretty big topic. For starters, I added just on reference.
But first, look at my ***very*** simple solution.
--SA

As your attempt to hide application was so naive, I would advice another naive suggestion which may satisfy you. Create a normal application without console and without any UI. To do this, you application option "Output type" should be "Windows Application". The simplest way to do this is to start from console application and to change Project's "Properties" => "Application" => "Output Type" to "Windows Application". Don't create any Forms or Windows, of course.

You can do more advanced variant of this. Suppose you want to start application with UI, but then press a button "Go to background" and remove UI which would continue to run as some invisible background application perhaps using some data defined by the used in the UI part. The simplest way to do this is to create a normal System.Windows.Forms application. Here is the simplest way: Your "Go to background" button should set an internal Boolean Background property of the main form and exit the System.Windows.Forms.Application. Another internal property (I called it InvisibleApplicationData of the type of the same name) can be returned from the form when it is closed. If this property Background is set, the rest of the code will run your invisible-part application:

C#
using System;
using System.Windows.Forms;

namespace Invisible {
     
    internal class InvisibleApplicationData { /*...*/ }
    internal static class InvisibleApplication {
        internal static void Run(InvisibleApplicationData data) { /*...*/ }
        //...
    } //class InvisibleApplication

    static class Program {
        
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MyUiPartForm form = new MyUiPartForm();
            Application.Run(form);
            //at this moment, application is invisible, now let's see
            //if we need to exit or continue in invisible phase:
            if (form.Background)
                InvisibleApplication.Run(form.InvisibleApplicationData);
        } Main

    } //class Program

} //namespace Invisible


Of course it will only hide your application from Alt+Tab and system tray, not from Task Manages, but who cares?
If you don't want to play this simple game, go with System Service as Tarakeshwar advised.
Start here:
http://msdn.microsoft.com/en-us/library/d56de412(v=VS.100).aspx[^].

—SA
 
Share this answer
 
v4
Comments
Tarakeshwar Reddy 29-Apr-11 22:06pm    
As usual great explanation and options. My 5.
Sergey Alexandrovich Kryukov 29-Apr-11 23:09pm    
Thank you, Tarakeshwar.
--SA
Sandeep Mewara 30-Apr-11 2:01am    
My 5 again!
Sergey Alexandrovich Kryukov 1-May-11 1:22am    
Thank you, Sandeep.
--SA
mohammadrefaie 3-May-11 8:53am    
actually it is perfect explain.
If you make your application just an icon in the system tray or call this.Hide() though you will have to call this.Show() at some point to reshow your application. this.text won't hide it in task manager (i though/hope) as task manager will display names of exe files (in processes tab). It won't even hide it in the Applications tab, it will just make it less obvious as it would appear as a blank item. To completely hide your application from the user is extremely unfriendly and often what viruses do to make themselves less detectable. Have a look at NotifyIcon class which will display an item in the system tray (otherwise known as Notification Area) but not Alt + Tab.

http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx[^]

http://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/[^]

Edit: If your application is never to be viewed by the user but to just run in the background look at Windows Services as suggested by Tarakeshwar Reddy
 
Share this answer
 
v2
Comments
mohammadrefaie 29-Apr-11 16:43pm    
i have just tried this :
this.Hide();
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;

but i have the same problem
Ed Nutting 29-Apr-11 16:46pm    
Try removing the this.WindowState and this.ShowInTaskbar sets as they may undo the work this.Hide() did.
mohammadrefaie 29-Apr-11 16:53pm    
sorry but i tried only hide() but it doesn't have any effect, my form appeared normally in task bar and notification area and its window appears too.
mohammadrefaie 29-Apr-11 17:02pm    
maybe hide() works in windows xp but not in 7.
Sergey Alexandrovich Kryukov 29-Apr-11 20:57pm    
This should work (my 5), but I would offer much more simple approach (2 variant) with is quite funny (but guaranteed to work :-)

Please see my solution.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900