VS 2008 Start application minimize in system tray-VBForums
Results 1 to 6 of 6

Thread: Start application minimize in system tray

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    185

    Start application minimize in system tray

    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:
    1. Public Class frmMain
    2.  
    3.     Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    4.         Select Case e.CloseReason
    5.             Case CloseReason.ApplicationExitCall
    6.                 'The user perfromed an action that caused your code to call Application.Exit.
    7.                 'You could go either way here but I'd suggest that you shouldn't be calling Application.Exit
    8.                 'if you don't actually want the application to exit.  In that case close the main form instead.
    9.                 e.Cancel = False
    10.             Case CloseReason.FormOwnerClosing
    11.                 'This form is a modeless dialogue, which you shouldn't be minimising to the system tray anyway.
    12.                 e.Cancel = False
    13.             Case CloseReason.MdiFormClosing
    14.                 'This form is an MDI child form, which you shouldn't be minimising to the system tray anyway.
    15.                 e.Cancel = False
    16.             Case CloseReason.None
    17.                 'If the reason can't be determined then something funky is going on so I'd suggest you let the form close.
    18.                 e.Cancel = False
    19.             Case CloseReason.TaskManagerClosing
    20.                 'The user pressed the End Task button on the Applications tab (NOT the Processes tab) of the Task Manager.
    21.                 '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
    22.                 'this way.  I'd suggest letting the form close but there would definitely be legitimate reasons for preventing it.
    23.                 e.Cancel = False
    24.             Case CloseReason.UserClosing
    25.                 'The user clicked the Close button on the title bar, pressed Alt+F4, selected Close from the
    26.                 'system menu or performed some action that caused your code to call the form's Close method.
    27.                 'Don't let the form close.
    28.                 e.Cancel = True
    29.                 Me.Visible = False
    30.                 ' Me.Hide()
    31.                 Me.ntfyI.Visible = True
    32.                 ' Me.ntfyI.ShowBalloonTip(1000)
    33.             Case CloseReason.WindowsShutDown
    34.                 'Windows is shutting down.
    35.                 'Definitely let the form close or you'll prevent Windows shutting down normally.
    36.                 e.Cancel = False
    37.         End Select
    38.  
    39.     End Sub
    40.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    41.         Application.Exit()
    42.     End Sub
    43.  
    44.  
    45.     Private Sub ntfyI_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ntfyI.MouseDoubleClick
    46.         Me.WindowState = FormWindowState.Normal
    47.         Me.Visible = True
    48.         Me.ntfyI.Visible = False
    49.  
    50.     End Sub
    51.  
    52.     Private Sub cmbExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbExit.Click
    53.         Application.Exit()
    54.     End Sub
    55.  
    56.     Private Sub frmMain_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
    57.         If Me.WindowState = FormWindowState.Minimized Then
    58.             Me.Visible = False
    59.             Me.ntfyI.Visible = True
    60.  
    61.         End If
    62.  
    63.     End Sub
    64.  
    65. End Class
    Attached Files Attached Files

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    4,995

    Re: Start application minimize in system tray

    I assume the question is "How to stop windows forms from showing up in the task bar ?" If so, you set the ShowInTaskBar property to False
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    185

    Re: Start application minimize in system tray

    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 !

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,562

    Re: Start application minimize in system tray

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,562

    Re: Start application minimize in system tray

    Quote Originally Posted by mrjohn View Post
    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    185

    Re: Start application minimize in system tray

    That was,thanks jmcilhinney !!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.