Hide form from Alt-Tab when first run


G

Guest

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.
 
Ad

Advertisements

G

Guest

Gary Bond said:
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.

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.
 
A

Andy

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
 
G

Guest

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...:cool:

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
 
J

Jeffrey Tan[MSFT]

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.
 
Ad

Advertisements

G

Guest

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
 
J

Jeffrey Tan[MSFT]

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.
 
A

Andy

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
 
Ad

Advertisements

G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top