Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Hide form from Alt-Tab when first run

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Bond - 09 Aug 2006 10:19 GMT
Hi All,

I would like to start a VB.Net 2.0 app minimised to the tray area. I use the
NotifyIcon component, set the form to start minimised by adding this to the
form.load event

       Me.WindowState = FormWindowState.Minimized
       Me.Hide()

and set the notifyicon component property to visible, so it shows in the
tray area. I have also set the showintaskbar property of the main form to
false.

All seems to work well when I run the app; the form does not show on the
taskbar, and I can see the notifiyicon's icon image in the task bar. The
problem is that the form icon is visible in the alt-tab switcher list.

However, if I double click the icon in the taskbar, which runs this code in
the notifyicon doubleclick event handler

       Me.Show()
       If (Me.WindowState = FormWindowState.Minimized) Then
           Me.WindowState = FormWindowState.Normal
           Me.Activate()
       End If
       NotifyIcon.Visible = False

and then minimise the form, which runs this code in the form.resize event
handler

       If (Me.WindowState = FormWindowState.Minimized) Then
           Me.Hide()
           NotifyIcon.Visible = True

then now the form icon does not appear in the alt-tab switcher.

I don't understand what is happening when the form is first shown, that is
not happening when I restore and minimise the form. I have looked in these
newsgroups and on the net but I could not find the answer, so any clues as to
how to accomplish hiding the form from the alt-tab list when it first runs
would be much appreciated. Thanks.
Mini-Tools Timm - 09 Aug 2006 13:55 GMT
> I would like to start a VB.Net 2.0 app minimised to the tray area. I use the
> NotifyIcon component, set the form to start minimised by adding this to the
[quoted text clipped - 10 lines]
> taskbar, and I can see the notifiyicon's icon image in the task bar. The
> problem is that the form icon is visible in the alt-tab switcher list.

I can't answer why it's happening, but it does in my tests too.  However, I
found that if I initialize the form's WindowState to
FormWindowState.Minimized in the initialization code, then remove the code
you have in the Load event, it seems to work as desired.

Signature

Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com

Andy - 09 Aug 2006 20:48 GMT
Gary,

What you need to do is create a class which inherits from
ApplicationContext.  Within this class you can declare your NotifcyIcon
and set it up and display it (in the contructor, for example).

You can handle the click or double click events for your NotifyIcon,
which will instanciate and display your form.

I assume you'd have an exit command on the icon; to do this, the menu
item which is to exit the application should call ExitThread on the
ApplicationContext.

Remember to override the ExitThreadCore to do any cleanup (such as
hiding then disposing of the NofityIcon).

HTH
Andy

> Hi All,
>
[quoted text clipped - 37 lines]
> how to accomplish hiding the form from the alt-tab list when it first runs
> would be much appreciated. Thanks.
Andy - 09 Aug 2006 20:49 GMT
Oh, for more detailed instructions, see this article:
http://www.windowsforms.net/articles/notifyiconapplications.aspx

> Hi All,
>
[quoted text clipped - 37 lines]
> how to accomplish hiding the form from the alt-tab list when it first runs
> would be much appreciated. Thanks.
Gary Bond - 10 Aug 2006 08:45 GMT
Hi both,

Many thanks for the information and the quick response - I really  
appreciate it.

I have been doing a bit of research and coding and have come up with a
couple of things:

1) If you run the app in the IDE then the icon seems to appear in the
alt-tab list for the first time - but if you run the exe itself then all is
well. So, in fact I was on the right track, and that maybe explains the
apparent difference we are finding between our two experiments, Timm.
2) Toolbar window styles don't show in the alt-tab list anyway. I tried this
but it did not represent the stlye of form I needed
3) For some reason the form often appears at the default 'location' set on
the properties window, not the default startposition. So you have to set the
form position yourself.

I ended up getting what I wanted in the short term by using this code:

Everytime you show the form:

       Me.Show()
       If (Me.WindowState = FormWindowState.Minimized) Then
           Me.WindowState = FormWindowState.Normal
           Me.CenterToScreen()
           Me.Activate()
       End If
       NotifyIcon.Visible = False

Resize event on the form:

       If (Me.WindowState = FormWindowState.Minimized) Then
           Me.Hide()
           NotifyIcon.Visible = True
       End If

FormLoad:

Me.Hide()

and set the form properties as

WindowsState = Minimized
ShowInTaskBar = false

Then when you run the app, (not in the IDE), at startup all you see is the
NotifyIcon's icon sitting in the tray area, and nothing in the alt-tab list.
When you double click the notifyicon the code above runs to show the form.
The only downside to this is that the form always goes in the middle of the
screen. I could not get it to work without it though, and on first showing it
ended up at the 'location' coordinates set on the form properties. Anyhow,
thanks Timm for the help.

Andy - thank you too. Your solution is the "proper" way to do things I
think, and I am going to try this just as soon as I have got this particular
app out of the way; time constraints mean I am running out of time to get
this done....welcome to the real world Gary...8-)

What I will do is to use your suggestions, have a good read of that article,
(that looks really good btw) and build myself a NotifyIcon skeleton app that
I can use whenever this comes up again.

so, thanks again both; Glad we got there and really appreciate the help,
cheers,
Gary
Jeffrey Tan[MSFT] - 11 Aug 2006 06:53 GMT
Hi Gary,

Glad to see Andy and Timm's replies can help you. Regarding you stating
that running in VS2005 IDE will get different result from running exe
directly, you may take care of 2 points:
1. F5 will start the application under debugger
2. VS2005 uses a hosting process to run the application by default which
may cause some strange problem. You may disable the hosting process in
Project setting->Debug->Enable the Visual Studio hosting process.

Anyway, if you need further help, please feel free to post, I will work
with you. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Gary Bond - 11 Aug 2006 10:52 GMT
Thanks Jeffrey,

I appreciate the help - I have got the initial problem sorted now, but I may
need come back as soon as I have digested the article Andy mentioned, (it
looked great but complicated - and I am not the world's best brain...ho ho)

cheers,
Gary

> Hi Gary,
>
[quoted text clipped - 30 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Jeffrey Tan[MSFT] - 11 Aug 2006 11:17 GMT
Ok, once you need any help, please feel free to post. :-)

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Andy - 11 Aug 2006 14:21 GMT
Gary,

Its actually not as tough as it sounds.  Just subclass
ApplicationContext.  Create a private member for the NotifyIcon.  In
your constructor, setup the NotifyIcon, including any menus you need.
Finally override ExitThreadCore, so that you can Dispose of the
NotifyIcon.

Then, instead of having:
Application.Run( new MainForm() );

You have:
Application.Run( new MyApplicationContext() );

The only change to the notifyicon you'll need is that instead of just
showing the form you'll need to create it as well.

HTH
Andy

> Thanks Jeffrey,
>
[quoted text clipped - 4 lines]
> cheers,
> Gary
Gary Bond - 14 Aug 2006 08:24 GMT
Hi Andy,
Thanks for the help. I have nearly fininshed the project so I can get a
chance to check this out. I will let you know how I get on in the next couple
of days.

cheers for this,
regards,
Gary

> Gary,
>
[quoted text clipped - 24 lines]
> > cheers,
> > Gary

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.