how to minimize a form into the system tray area?

A

assaf

hi all

my app has a 'notifyIcon'.
when i close its window,
i want it to behave like MSN Messenger.
i want it to minimize itself
into the system tray area.

i want to imitate
the process by which this occurs.
the window seems to minimize
itself in stages into the tray.

how can i minimize my form into the system tray area?


assaf
 
P

Peter Jausovec

Hi,

Put this code in form Closing event:

e.Cancel = true;
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;

This will cancel the form close event and put the app in system tray.
 
J

John M Deal

It may go without saying but to actually get it into the tray though
you'll need to add a notify icon control to your form, give it an icon
to display, and then make if visible or invisible based on whether or
not the application is hidden in the tray or not. Of course you could
forget about the visible/invisible step if you always want the icon in
the tray.

Also if you plan to ever exit the application you may want to put a
right click context Exit menu on the form. To make this work you'll
want to surround Peter's code with some type of check to see if the
closing code came from a close event that you want to minimize or one
that you really want to close the application with. While it isn't a
huge deal, if you forget this step you'll end up with an app that
becomes quite a pain to shut down and users that aren't happy about that
(and yes I know because I learned it the hard way).

Have A Better One!

John M Deal, MCP
Necessity Software
 
A

assaf

hi guys.

u did not read my post.

u see,
i already have an app.
with all the features that u mention.

however,
when i close it,
and it becomes hidden,
i want that to happen just as
MSN Messenger does it.

the window slowly minimizes itself into
the tray area.

how can i do that?
simply making the form hidden
confuses the user.
he must understand that the app is
still running in the tray.

this can be accomplished as
MSN Messenger.


assaf
 
J

John M Deal

Whoops :) Sorry about that. Afraid I can't help with setting up a
shrinking form but the way we got around the confusion was to display a
notification form the first time the user "closed" the app to the tray
(we stored the "seen it" value in their user Isolation Storage). The
notification let them know what was happening then we didn't bug them
with it again. Sorry for the confusion and the lack of real help.

John M Deal, MCP
Necessity Software
 
G

Guest

Hi assaf

You can simulate this using a Timer - when you want to 'minimize' the window
to the tray, you set the window height to 0, the opacity to something small,
and set the form location to a different position in the timer event until
you get to the system tray / notification area. I'm not sure how you get the
desktop position of the Notification Area though - I'm sure someone will give
you the answer!

Nigel Armstrong

Code like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
deltaX = (destX - Me.Location.X) / 200
deltaY = (destY - Me.Location.Y) / 200
Me.Height = 0
Me.Opacity = 2
Me.Timer1.Enabled = True
End Sub


Dim destX As Integer = 1000
Dim destY As Integer = 768
Dim deltaX As Double
Dim deltaY As Double


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.Location = New Point(Me.Location.X + deltaX, Me.Location.Y +
deltaY)
If Me.Location.X = destX Then
Me.Timer1.Enabled = False
Me.WindowState = FormWindowState.Minimized
Me.ShowInTaskbar = False
End If
End Sub
 
G

Guest

On the other hand, this emulation is quite lame...you should read up on
DrawAnimatedRects! I've got some (bad!) code that exercises this method and
gives a much more satisfying minimze effect, including knowing where the
Notification Area is...let me know if you want me to post it!

HTH

Nigel Armstronng
 
A

assaf

hi nigel

yes.
i would.

thnk you

assaf


Nigel Armstrong said:
On the other hand, this emulation is quite lame...you should read up on
DrawAnimatedRects! I've got some (bad!) code that exercises this method and
gives a much more satisfying minimze effect, including knowing where the
Notification Area is...let me know if you want me to post it!

HTH

Nigel Armstronng
 

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