Frage

I'm using Visual Studio Express 2013 to write a formless VB.Net application that will start and remain iconized in the systray section.

I googled for infos on how to get started but didn't find much.

Would anyone have pointers to get started?

Thank you.


Edit: If you need to add support for a single left click, add the following code to the NotifyIcon1 object so that the application doesn't also open the pop-up menu:

Private Sub LeftClick(sender As Object, e As EventArgs) Handles NotifyIcon1.Click
    'Work-around to prevent Windows from triggering Click then right-click
    Dim MyButton As System.Windows.Forms.MouseEventArgs = e
    If MyButton.Button = MouseButtons.Left Then
        'Find how to put focus on msgbox
        MessageBox.Show("Left click")
    End If
End Sub
War es hilfreich?

Lösung

Creating an application that lives in the system tray is easy, but it is not entirely obvious how to do so in Visual Studio.

1) First, create a new Windows Application project in Visual Studio.NET. This can be either Visual Basic or C#

2) Drag a Notifyicon control and a ContextMenu control from the toolbox onto the form.

3) Click on the NotifyIcon control that you just added, and set the Icon property to whatever icon you want your application to have.

4) Set the ContextMenu property of the Notifyicon to the context menu that you added to your project.

5) Right click on the Context Menu control, and select Edit. Since this menu will be the right-click menu for your tray icon, you will want to add the items that the user will see. Make sure to add an Exit menu item.

6) Double click the Exit menu item, and add the following code:

Me.Close

7) Now for the important settings. Click on the form, and go to the Properties window. Set the following settings:

FormBorderSize: Fixed Tool Window
WindowState: Minimized
Opacity: 0%
ShowInTaskbar: False

The key thing to remember is that the default form is not to be used for application functionality, it is only used as the hidden background window. If you want to create a new window, you can just add another form to your application.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top