Close to tray

S

Shawn

Hi. I've created an application that can run in the system tray. The way it
works now I have to click a button to "send" the application to the system
tray, but I want the application to run in the tray whenever the user clicks
either the minimize or close button on the form.. How can I do that? I
have to be able to tell the application not to exit whenever the forms exit
button is clicked..

Any help is greatly appreciated!
Shawn
 
T

Tim Gallivan

Try this:

Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060

If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_CLOSE Then
' User clicked close button
Me.Hide()
Return
End If

MyBase.WndProc(m)

End Sub 'WndProc
 
H

Herfried K. Wagner [MVP]

* "Shawn said:
Hi. I've created an application that can run in the system tray. The way it
works now I have to click a button to "send" the application to the system
tray, but I want the application to run in the tray whenever the user clicks
either the minimize or close button on the form.. How can I do that? I
have to be able to tell the application not to exit whenever the forms exit
button is clicked..

<http://groups.google.de/groups?ie=UTF-8&q=group:*dotnet*+minimize+to+tray>
 
S

Shawn

Works great!!
Thanks Tim

Shawn



Try this:

Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060

If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_CLOSE Then
' User clicked close button
Me.Hide()
Return
End If

MyBase.WndProc(m)

End Sub 'WndProc
 

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