Minimize to system tray

Visual basic 2008 Express

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 231324 Views - Last Post: 27 December 2010 - 12:16 AM Rate Topic: -----

#16 joker100   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-July 09

Re: Minimize to system tray

Posted 13 July 2009 - 08:25 PM

View PostLoveIsNull, on 13 Jul, 2009 - 05:41 PM, said:

Attachment attachment

Don't understand how to drag a NotifyIcon to the form or e.Cancel = True?
This instance of e is a FormClosingEventArgs object, Cancel is a boolean (true or false) property that decides if the application should cancel the close (true means don't close).

Note that e is not always FormClosingEventArgs, the specific type depends but generally speaking it is some kind of event argument class.


i won't get the windows maximized. When i take the value to normal. The application hanging
Was This Post Helpful? 0
  • +
  • -

#17 Cocacolalover   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 03-September 09

Re: Minimize to system tray

Posted 03 September 2009 - 04:09 PM

Quote


i won't get the windows maximized. When i take the value to normal. The application hanging


Put Me.Visible = True first to Me.WindowState = FormWindowState.Normal

like
 Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick

		NotifyIcon1.Visible = False
		Me.Visible = True
		Me.WindowState = FormWindowState.Normal

	End Sub


Regards ;)

This post has been edited by Cocacolalover: 03 September 2009 - 04:10 PM

Was This Post Helpful? 1
  • +
  • -

#18 Rihoj   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-September 09

Re: Minimize to system tray

Posted 06 September 2009 - 12:55 PM

Ok, so I have been using your code, and it has been working wonderfully. The one issue I am having though...how do I get the program to actually close. Like say someone right clicks on the nfi, and does not want the window to show, but instead to exit. How do I do this? I have tried adding just
me.close()
but this goes back to the form closing function, and just minimizes it.

Please help me. I do not have any code different than what is showing already here.
Was This Post Helpful? 0
  • +
  • -

#20 piman314   User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 169
  • Joined: 07-August 09

Re: Minimize to system tray

Posted 06 September 2009 - 01:04 PM

try having a variable outside of the function that stores wether you actually want to close it or not
'in class
Dim DoClose As Boolean = false

'in FormClosing Event
If Not DoClose
	e.Cancel = true
	Me.WindowState = FormWindowState.Minimized
	Me.Visible = false
	nfi.Visible = true
Else
	nfi.Visible = false
End If

'In Exit Button click
DoClose = true
Me.Close()


Was This Post Helpful? 1

#21 Rihoj   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-September 09

Re: Minimize to system tray

Posted 06 September 2009 - 01:08 PM

Thank you greatly. This helped me so much. It works, and now it will work just as I needed. Thanks.
Was This Post Helpful? 0
  • +
  • -

#22 fhugas   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-October 09

Re: Minimize to system tray

Posted 22 October 2009 - 01:06 PM

Or you could just use
End

and the program will end right away
Was This Post Helpful? 0
  • +
  • -

#23 Guest_Pratik M Mahajan*


Reputation:

Re: Minimize to system tray

Posted 12 February 2010 - 10:18 PM

'Note that you must select NotifyIcon1 from Toolbox Itmes, 3 buttons and set any icon to NotifyIcon1 in icon property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WindowState = FormWindowState.Minimized
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Exit()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
NotifyIcon1.Visible = True
End Sub

Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
End Sub
Was This Post Helpful? 0

#24 programmer4life   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 25-February 10

Re: Minimize to system tray

Posted 25 February 2010 - 08:54 PM

Just wanna say thanks to everyone, this thread helped me out a lot too!!
Was This Post Helpful? 1
  • +
  • -

#25 Guest_BAK*


Reputation:

Re: Minimize to system tray

Posted 15 April 2010 - 05:45 PM

can some one give me an email to send them code for vb 2010 and have you do it for me for i don't get this at all


email me at {REMOVED}
Was This Post Helpful? 0

#26 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Minimize to system tray

Posted 15 April 2010 - 06:41 PM

View PostBAK, on 15 April 2010 - 03:45 PM, said:

can some one give me an email to send them code for vb 2010 and have you do it for me for i don't get this at all


email me at {REMOVED}


We're not a code writing service here

Sorry but we can not give you the entire code to solve your problem. We are here to assist in solving problems with code you have written, with any error messages you are getting or what isn't working the way that you expect it to, we would be more than happy to help you with those problems. If there is a topic that you don't understand we would be more than happy to help you with that as well. Make sure to post any code with in code tags like below.

:code:

Be sure to visit our tutorial and snippet areas or read the FAQS at the top of the forums. Also, take a moment to read the rules about posting topics.

Thank you for helping us to help you solve your problem.
Was This Post Helpful? 0
  • +
  • -

#27 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Minimize to system tray

Posted 15 April 2010 - 09:16 PM

My 2 cents, I like to check the e.CloseReason before doing anything.
If windows is shutting down my app should probably close with it. Just another thought. :online2long:
Was This Post Helpful? 0
  • +
  • -

#28 Guest_phamhongha*


Reputation:

Re: Minimize to system tray

Posted 27 October 2010 - 07:56 AM

View PostLoveIsNull, on 13 July 2009 - 05:41 PM, said:

Attachment attachment

Don't understand how to drag a NotifyIcon to the form or e.Cancel = True?
This instance of e is a FormClosingEventArgs object, Cancel is a boolean (true or false) property that decides if the application should cancel the close (true means don't close).

Note that e is not always FormClosingEventArgs, the specific type depends but generally speaking it is some kind of event argument class.


ThankS all,
I've read and found interesting things in your discuss.
Inherit from your code, I've finish this one and hope it will help you.
1. Drag NotifyIcon (in the Toolbar)onto your form then name it nfi
2. creat a button (to set the from to normal state).
3. paste these codes (I am working in VB2005):
Public Class Form1
    Dim MClose As Boolean = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Nfi.Icon = Me.Icon
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        If MClose = False Then
            e.Cancel = True
        Else
            e.Cancel = False
        End If
        Me.Visible = False

        ' 
    End Sub

    Private Sub Nfi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Nfi.Click
    End Sub

    Private Sub Nfi_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Nfi.MouseDoubleClick
        Me.Visible = True
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MClose = True
    End Sub
End Class
'A Bad Coder From VietNam


This post has been edited by macosxnerd101: 27 October 2010 - 08:22 AM
Reason for edit:: Added code tags. Please use them in the future.

Was This Post Helpful? 0

#29 Jack Eagles1   User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 187
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Minimize to system tray

Posted 27 October 2010 - 08:00 AM

WHY WHY WHY? Revive a 6 month old zombie topic? WHY?
Was This Post Helpful? 0
  • +
  • -

#30 Guest_Sumal T.Jayaranga*


Reputation:

Re: Minimize to system tray

Posted 27 December 2010 - 12:16 AM

View PostPsychoCoder, on 31 May 2008 - 05:09 PM, said:

My bad, I actually forgot a single line of code that will stop the application from closing. I forgot to add e.Cancel = True, telling it to not close the application


Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        'First minimize the form
        Me.WindowState = FormWindowState.Minimized

        'Now make it invisible (make it look like it went into the system tray)
        Me.Visible = False

        'Cancel the closing of the application
        e.Cancel = True

        nfi.Visible = True

        MsgBox("FTProgram has been minimized to the task bar.")

End Sub


One addition :)
NotifyIcon must have a icon to appear in task bar
nfi.Icon = Me.Icon


Was This Post Helpful? 0

  • (2 Pages)
  • +
  • 1
  • 2