Hi !
I've created one project where I want to start application directly minimize in system tray,it is there but I can see it also in taskbar.
this is the code , and also project is attached
Thanks !
vb.net Code:
Public Class frmMain
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Select Case e.CloseReason
Case CloseReason.ApplicationExitCall
'The user perfromed an action that caused your code to call Application.Exit.
'You could go either way here but I'd suggest that you shouldn't be calling Application.Exit
'if you don't actually want the application to exit. In that case close the main form instead.
e.Cancel = False
Case CloseReason.FormOwnerClosing
'This form is a modeless dialogue, which you shouldn't be minimising to the system tray anyway.
e.Cancel = False
Case CloseReason.MdiFormClosing
'This form is an MDI child form, which you shouldn't be minimising to the system tray anyway.
e.Cancel = False
Case CloseReason.None
'If the reason can't be determined then something funky is going on so I'd suggest you let the form close.
e.Cancel = False
Case CloseReason.TaskManagerClosing
'The user pressed the End Task button on the Applications tab (NOT the Processes tab) of the Task Manager.
'You could go either way here too. It really depends on your app and if you don't want the user to be able to exit
'this way. I'd suggest letting the form close but there would definitely be legitimate reasons for preventing it.
e.Cancel = False
Case CloseReason.UserClosing
'The user clicked the Close button on the title bar, pressed Alt+F4, selected Close from the
'system menu or performed some action that caused your code to call the form's Close method.
'Don't let the form close.
e.Cancel = True
Me.Visible = False
' Me.Hide()
Me.ntfyI.Visible = True
' Me.ntfyI.ShowBalloonTip(1000)
Case CloseReason.WindowsShutDown
'Windows is shutting down.
'Definitely let the form close or you'll prevent Windows shutting down normally.
e.Cancel = False
End Select
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ntfyI_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ntfyI.MouseDoubleClick
Me.WindowState = FormWindowState.Normal
Me.Visible = True
Me.ntfyI.Visible = False
End Sub
Private Sub cmbExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbExit.Click
Application.Exit()
End Sub
Private Sub frmMain_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
If Me.WindowState = FormWindowState.Minimized Then
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
Thanks Niya !
I knew about that but not is that I want,I want my app to be in taskbar as long it is not on system tray and to be in sys tray as long it is not in taskbar,not in both.Also I want,when I run my app, to go first in sys tray.
Thanks !
Also I want,when I run my app, to go first in sys tray.
Just set the ShowInTaskbar property of the form to False and the WindowState to Minimized at design time. In the Shown event handler, set Visible to False and WindowState to Normal. When the user uses the NotifyIcon, e.g. on its DoubleClick event, you set ShowInTaskbar and Visible to True for the form and Visible to False for the NotifyIcon.
It is what you want. You simply need to make sure that the ShowInTaskbar property of the form and the Visible property of the NotifyIcon are always opposite values. If the app is "in the tray" then the NotifyIcon.Visible is True and Form.ShowInTaskbar is False. If the app is not "in the tray" then NotifyIcon.Visible is False and Form.ShowInTaskbar is True.