在Windows启动上运行程序无需表格



我基本上要显示的是:

notifyicon.visible = true

我的意思是在窗口启动时显示托盘图标,但不应显示程序表格,我该如何实现?

我知道,通过添加注册表,您可以在下面的启动示例上运行该程序

Dim regkey As RegistryKey
        regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
        If (runonstartupToolStripMenuItem.Checked = True) Then
            ' Add the value in the registry so that the application runs at startup
            regkey.SetValue("Your Application Name", Application.ExecutablePath.ToString())
        Else
            ' Remove the value from the registry so that the application doesn't start
            regkey.DeleteValue("Your Application Name", False)
        End If

,但这将运行整个程序,并会使表单显示,除非用户手动启动它,否则我不需要。

将此代码添加到您的表单:

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Me.Hide()                    ' <= Required
      Me.ShowInTaskbar = False     ' <= Required
      NotifyIcon1.Visible = True  
      NotifyIcon1.ShowBalloonTip(10000)
 End Sub

当窗口启动时程序打开时,应使用唯一参数打开,当发现唯一参数时,表单将被隐藏相反,如果用户打开程序,则不会具有参数,然后表单可以显示。

我正在使用复选框进行设置并取消设置:

Private Sub cbStartup_CheckedChanged(sender As Object, e As EventArgs) Handles cbStartup.CheckedChanged
        Dim applicationName As String = Application.ProductName
        Dim applicationPath As String = Application.ExecutablePath
        If cbStartup.Checked = True Then
            Dim regKey As Microsoft.Win32.RegistryKey
            regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun", True)
            regKey.SetValue(applicationName, """" & applicationPath & """")
            regKey.Close()
        Else
            Dim regKey As Microsoft.Win32.RegistryKey
            regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun", True)
            regKey.DeleteValue(applicationName, False)
            regKey.Close()
        End If
    End Sub

在Windows 10 64bit上进行VS 2015运行的测试。

相关内容

最新更新