Minimize to tray?

You should use the NotifyIcon component.

When you hit Minimize, Hide the form.
Then, when you want to restore the form (ContextMenu, perhaps) you just show the form and set the WindowState to Normal. :)
 
ok i got it working with a button click, but how do i do it when the user clicks the close/exit button?

Code:
    Private Sub trayicon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles trayicon1.MouseDown
        Me.Show()
    End Sub
    Private Sub form1_close()
        Me.Hide()
    End Sub

    Private Sub XButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XButton1.Click
        Me.Hide()
    End Sub
XButton is a component i have, Windows XP style button.
 
Do you want the window to minimize to the system tray just like Windows Messenger threatens me when I start it up and then press the X?

You'd have to handle the Form's Closing event, set the Cancel property in the EventArgs to True and then Hide the form. :)
XButton... what is that?
 
you can have buttons like
Windows XP
Normal(classic windows)
Office XP Flat
and Aqua(mac kinda look)

where is the cancel property

i found Cancel button in Form1 properties and set the thing as XButton1 (button that hides form) but it still ends the program...
 
Last edited:
Start from the beginning and work towards the end.
You have to first handle the Form's Closing event.
Within the Form's Closing event, you should be able to find the Cancel property as a member of e, the eventargs.
To set it to True, you do this:
e.Cancel = True
Then, you hide the form of course.
:)
 
What are you actually trying to do, have an application that can never be closed, just minimised or what is it you want.
If you want to prevent it from being closed, why don't you hide the controlbox on the form, this will do it for you. You could then have a minimise button and as long as showInTaskBar is true, you have what you want, I think, but then I am not sure what you want.
 
its ok, i got it now

[edit]Links to executable files are not allowed. Please post source code and related files only.[/edit]
 
Last edited by a moderator:
Back
Top